2014-10-07 110 views
0

我想图像保存到这个'http://198.164.241.108/~bss/api/images/upload_images';位置PHP图片上传到远程服务器

我尝试以下

$url = 'http://198.164.241.108/~bss/api/images/upload_images'; 

$img = $_FILES['image']['tmp_name']; 

file_put_contents($img, file_get_contents($url)); 

使用curl

$ch = curl_init(); 

curl_setopt($ch, CURLOPT_POST, true); 

curl_setopt($ch, CURLOPT_POSTFIELDS, array('file' => $_FILES["image"]["tmp_name"])); 

curl_setopt($ch, CURLOPT_URL, '`http://198.164.241.108/~bss/api/images/upload_images`'); 

curl_exec($ch); 
curl_close($ch); 

但是这两个不工作

+0

当然,它不会工作 - 你需要模拟表单提交。实现它的最好方法 - 借助cURL函数。分析从表单发送的数据和http://stackoverflow.com/questions/3085990/post-a-file-string-using-curl-in-php – Cheery 2014-10-07 06:17:52

回答

0

据我所知,它是远程服务器,所以你必须连接到该服务器并使用ftp_put()。另外,要使用全局变量$_FILES,首先需要使用一些HTML表单(我希望你只是在你的问题中跳过了这个明显的部分)。