简体   繁体   English

在使用curl的php上传文件时,此链接中的“目标脚本”是什么?

[英]what is the 'destination script' in this link to upload a file using php with curl?

This is the past question I've found while I was google. 这是我在Google时发现的过去的问题 The first answer is pretty simple and I don't understand. 第一个答案很简单,我听不懂。

The whole script is here, 整个脚本在这里,

$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);

This is what I don't understand, 这是我不明白的

curl_setopt($ch, CURLOPT_URL, "http://www.example.com/your-destination-script.php");

this is the place to define destination url. 这是定义目标网址的地方。 But what should I write in there to upload a file from here, 但是我应该写些什么来从这里上传文件,

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

Please someone explain me or please try. 请有人向我解释或尝试。 I'm new to PHP. 我是PHP新手。

The answer is pretty simple. 答案很简单。 The destination script(lets say, a PHP file here) is the script that uses the $_POST array to get the file contents using file_get_contents() function(or if a JSON object, it decodes it using json_decode() function) 目标脚本(这里是一个PHP文件)是使用$_POST数组通过file_get_contents()函数获取文件内容的脚本(或者,如果是JSON对象,则使用json_decode()函数对其进行解码)

So, basically, this is the script to which the image is sent for uploading. 因此,基本上,这是图像要发送到的脚本。 Can be any script on any site (if the site allows, uploading like this). 可以是任何站点上的任何脚本(如果站点允许,可以这样上传)。 There are times when sites require a login ID, or a token ID for this, which is also passed by using CURL_POSTFIELDS and checked in the PHP script if the login ID or token ID was real or not. 有时,网站需要登录ID或令牌ID,这也可以通过使用CURL_POSTFIELDS传递,并在PHP脚本中检查登录ID或令牌ID是否真实。 Just a security measure :) 只是一个安全措施:)

Understood?? 明白? :) :)

Generally, the destination script is a script used to connect to a site's API etc etc :) 通常,目标脚本是用于连接到站点的API等的脚本:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM