当浏览器将文件上载到服务器时,它会发送包含文件内容的HTTP POST请求.
你必须复制它.
使用PHP,最简单(或至少,最常用)的解决方案可能适用于curl.
如果您查看可以使用curl_setopt设置的选项列表,您将看到以下选项:CURLOPT_POSTFIELDS(引用):
The full data to post in a HTTP “POST”
operation.
To post a file,
prepend a filename with @ and use the
full path.
This can either be
passed as a urlencoded string like
‘para1=val1¶2=val2&…’ or as an
array with the field name as key and
field data as value.
If value is
an array, the Content-Type header will
be set to multipart/form-data.
没有经过测试,但我想这样的事情应该可以解决 – 或者至少帮助你开始:
$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_setopt($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_exec返回结果,而不是输出结果>正在使用POST,而不是GET>发布一些数据,包括文件 – 在文件路径前注意@.