[英]what is the 'destination script' in this link to upload a file using php with curl?
这是我在Google时发现的过去的问题 。 第一个答案很简单,我听不懂。
整个脚本在这里,
$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");
这是定义目标网址的地方。 但是我应该写些什么来从这里上传文件,
curl_setpopt($ch, CURLOPT_POSTFIELDS, array(
'file' => '@/..../file.jpg', // you'll have to change the name, here, I suppose
// some other fields ?
));
请有人向我解释或尝试。 我是PHP新手。
答案很简单。 目标脚本(这里是一个PHP文件)是使用$_POST
数组通过file_get_contents()
函数获取文件内容的脚本(或者,如果是JSON对象,则使用json_decode()
函数对其进行解码)
因此,基本上,这是图像要发送到的脚本。 可以是任何站点上的任何脚本(如果站点允许,可以这样上传)。 有时,网站需要登录ID或令牌ID,这也可以通过使用CURL_POSTFIELDS
传递,并在PHP脚本中检查登录ID或令牌ID是否真实。 只是一个安全措施:)
明白? :)
通常,目标脚本是用于连接到站点的API等的脚本:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.