【发布时间】:2016-03-17 12:49:42
【问题描述】:
如何从我的网站(服务器)发布文件(路径 /var/www/ httpdocs/domain.com /images/image.jpg)到另一个网站?
我试过了:
$ch = curl_init();
$Url = "http://domain.com/insert.php";
$cookie_file = 'cookies.txt';
$file_name_with_full_path = realpath('/images/image.jpg');
$fields = array(
'type' => urlencode(1),
'category' => urlencode(1),
'title' => "Some title",
'description' => "Some description",
'file' => '@'.$file_name_with_full_path
);
$fieldsTrim = http_build_query($fields);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fieldsTrim);
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_COOKIEFILE, realpath($cookie_file));
curl_setopt($ch, CURLOPT_COOKIEJAR, realpath($cookie_file));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$output = curl_exec($ch);
但它不起作用..
它会发送除文件以外的所有内容...
谢谢
【问题讨论】:
-
远程服务器中的文件路径是否缺少
$_POST['file']?$fieldsTrim = http_build_query($fields);$fields是什么?我在您的代码中没有看到$fields -
对不起,我更新了代码。
-
所以
$_POST['file']是空的?还有语法错误`'file' => '@'.$file_name_with_full_path)`) -
No $_POST['file'] 在我尝试发布图片时不为空。语法错误只是我点击这里。
-
我模拟你的代码,然后用这个c2n.me/3rBv1yp 一切都好;