2015-12-22 57 views
0

我有兩個域名一個是stgportal,另一個是stg.I要低於如何將圖像從一個域上傳到另一個域?

move_uploaded_file($_FILES['ThumbnailImage']['tmp_name'],"http://stg.eminencesystem.com/assets/images/th/".$thimg) 

給出從stgportal到stg.My代碼,上傳圖片顯示錯誤:failed to open stream: HTTP wrapper does not support writeable connections

我怎麼能解決這個問題?

回答

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; 
相關問題