Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
&引用@/路径/to/a/file";在PHP中,它是什么意思?_Php_String_Filepath - Fatal编程技术网

&引用@/路径/to/a/file";在PHP中,它是什么意思?

&引用@/路径/to/a/file";在PHP中,它是什么意思?,php,string,filepath,Php,String,Filepath,我无意中看到了以下代码示例: $image = 'file/path'; $code = $tmhOAuth->request('POST', 'https://upload.twitter.com/1/statuses/update_with_media.json', array( 'media[]' => "@{$image}", 'status' => "Don't slip up" // Don't give up.. ), true,

我无意中看到了以下代码示例:

$image = 'file/path';
$code = $tmhOAuth->request('POST', 'https://upload.twitter.com/1/statuses/update_with_media.json',
  array(
    'media[]'  => "@{$image}",
    'status'   => "Don't slip up" // Don't give up..
  ),
  true, // use auth
  true  // multipart
);
令人困惑的是“@{$image}”,文件路径前面的“at”符号是什么?
谢谢

看看问题中的代码,@'符号只是字符串变量的一部分。作为一种语言,它对PHP没有特殊意义

它可能对传递给它的代码有特殊意义,但对PHP来说,它只是一个以“@”符号开头的简单字符串变量


从上下文来看,我猜它大概是作为JSON对象的一部分传递给Twitter的。在这种情况下,它可能对Twitter有特殊的意义,但我不知道API,所以我不能肯定地告诉你。在任何情况下,这都不是PHP问题。

我不知道您使用的是什么库,但我假设它在内部使用扩展名,因为这就是您指定将路径卷曲到要上载的文件的方式,即在路径前面加上
@
。见此:


PHP中的
{$expression}
语法与Ruby中的
#{expression}
语法一样,是一种使用PHP的方法

因此,
“@{$image}”
相当于
“@”。$image

@
用于将常规POST变量值与要上载的文件名进行区分。您的库必须在内部使用curl模块或遵循相同的约定

设置POST变量时,如果任何值的前缀为
@
,则将其视为要上载的文件名:

curl_setopt($curl, CURLOPT_POSTFIELDS, array(
    'regular_variable' => 'value',
    'some_file' => '@/path/to/filename', // this is treated as a file to upload
));
这不是很广为人知,如果程序员没有意识到这一点,可能会导致安全问题。这可以通过将查询字符串传递给CURLOPT_POSTFIELDS()来禁用


这对PHP本身没有特殊意义。

很高兴知道,如果不是作为文件上传,可以使用http\u build\u query()在周围处理“@…”!谢谢
curl_setopt($curl, CURLOPT_POSTFIELDS, array(
    'regular_variable' => 'value',
    'some_file' => '@/path/to/filename', // this is treated as a file to upload
));