"@/path/to/a/file"在PHP中,这是什么意思? [英] "@/path/to/a/file" in PHP, what does it mean?

查看:79
本文介绍了"@/path/to/a/file"在PHP中,这是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我偶然发现了以下代码示例:

I have stumbled to following code example:

$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"符号是什么? 谢谢!

The confusing bit is "@{$image}", what that "at" sign does in front of the file path? Thanks!

推荐答案

我不知道您使用的是哪个库,但我认为它使用的是示例:

I don't know what library you're using, but I assume it uses the PHP cURL extension internally, because that's how you specify to cURL the path to a file that you want to upload, i.e., by prepending the path with an @. See this example from the PHP manual:

<?php

/* http://localhost/upload.php:
print_r($_POST);
print_r($_FILES);
*/

$ch = curl_init();

$data = array('name' => 'Foo', 'file' => '@/home/user/test.png');

curl_setopt($ch, CURLOPT_URL, 'http://localhost/upload.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

curl_exec($ch);

这篇关于"@/path/to/a/file"在PHP中,这是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆