Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.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
什么是';目标脚本';在这个链接中,使用带有curl的php上传文件?_Php_Http_Curl - Fatal编程技术网

什么是';目标脚本';在这个链接中,使用带有curl的php上传文件?

什么是';目标脚本';在这个链接中,使用带有curl的php上传文件?,php,http,curl,Php,Http,Curl,我在谷歌的时候就发现了。第一个答案很简单,我不明白 整个剧本都在这里 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://www.example.com/your-destination-script.php"); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLO

我在谷歌的时候就发现了。第一个答案很简单,我不明白

整个剧本都在这里

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/your-destination-script.php");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setpopt($ch, CURLOPT_POSTFIELDS, array(
        'file' => '@/..../file.jpg',    // you'll have to change the name, here, I suppose
        // some other fields ?
));
$result = curl_exec($ch);
curl_close($ch);
这是我不明白的

curl_setopt($ch, CURLOPT_URL, "http://www.example.com/your-destination-script.php");
这是定义目标url的地方。但是我应该写些什么来上传文件呢

curl_setpopt($ch, CURLOPT_POSTFIELDS, array(
        'file' => '@/..../file.jpg',    // you'll have to change the name, here, I suppose
        // some other fields ?
));

请有人给我解释一下或者试试看。我是PHP新手。

答案很简单。目标脚本(假设这里是一个PHP文件)是一个脚本,它使用
$\u POST
数组使用
file\u get\u contents()
函数获取文件内容(或者如果是JSON对象,则使用
JSON\u decode()
函数对其进行解码)

因此,基本上,这是将图像发送到其中进行上载的脚本。可以是任何站点上的任何脚本(如果站点允许,像这样上载)。有时站点需要一个登录ID或令牌ID,如果登录ID或令牌ID是真实的或非真实的,则还可以使用
CURL\u POSTFIELDS
传递该ID,并在PHP脚本中进行检查。只是一个安全措施:)

明白吗??)


通常,目标脚本是用于连接站点API等的脚本:)

file'=>'@/…/file.jpg'是您需要上传的文件的路径是的,我明白了。但是我应该在destination_script.php上写些什么呢?非常感谢!!!我理解这个概念。因此,目标脚本负责处理接收到的文件。你有什么样的脚本吗?我只想从localhost上传一个文件到远程服务器。如果您有任何示例脚本来处理收到的文件?请TinyPNG是一个允许通过CURL上传图像的网站,请看这里。向下滚动,直到看到带有CURL的PHP:)