我有两个域名是stgportal而另一个是stg.I我想将图像从stgportal上传到stg.My代码如下:
move_uploaded_file($_FILES['ThumbnailImage']['tmp_name'],"http://stg.eminencesystem.com/assets/images/th/".$thimg)
显示错误:failed to open stream: HTTP wrapper does not support writeable connections
我该如何解决这个问题?
答案 0 :(得分:0)
您可以使用CURL像这样安全地将文件发送到另一台服务器
在stgportal方面
function sendImageToServer($path = "", $file = null)
{
$post_url = "http://stg.eminencesystem.com/post_file";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_URL, $post_url);
//most importent curl assues @filed as file field
$post_array = array(
"folder_name" => $path
);
if ((version_compare(PHP_VERSION, '5.5') >= 0)) {
$post_array['file'] = new CURLFile($file);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, TRUE);
} else {
$post_array['file'] = "@" . $file;
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_array);
$response = curl_exec($ch);
return $response;
}
在stg方面
$ImagePath = "/var/www/html/assets/";
$files = $_FILES;
$folder_name = utf8_decode($_POST['folder_name']);
$savepath = $ImagePath . $folder_name . $files['name'];
copy($file['tmp_name'], $savepath);
echo 1;
exit;