2013-03-05 72 views
1

編寫代理文件上傳的應用程序。我使用CURL來發布文件,但有一些問題。張貼到腳本是好的,它從腳本發佈到下一個服務器是問題。我不斷從服務器收到此錯誤:PHP Curl文件上傳多部分邊界

「的請求被拒絕,因爲沒有多邊界發現」

這裏是我的代碼:

  $post = $_POST; 

      // allow for file upload proxying 
      if(!empty($_FILES)){ 
        // add to post data 
        foreach($_FILES as $name => $upload){ 
          $post[ $name ] = '@' . $upload[ 'tmp_name' ] . ';type=image/png'; 
        } 
      } 

      // init curl 
      $ch = curl_init($url); 

      // configure options 
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 

      // post data 
      if(!empty($post)){ 
        curl_setopt($ch, CURLOPT_POST, true); 
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
        // for file uploads, multi-part 
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
          'Content-type: multipart/form-data;' 
        )); 
      } 

      // execute and get return value 
      $return = trim(curl_exec($ch)); 

      // cleanup 
      curl_close($ch); 
      unset($ch); 

一切我在網上看了認爲,這應該工作,而且設置標題內容類型是不必要的,但是當我刪除內容類型時,我得到這個錯誤:

「該請求不包含multipart/form-data或multipart/mixed流,內容類型標題爲空「

有什麼想法?在此先感謝

回答

0

不確定到底是什麼問題,但我在本地工作,當我發佈這個。將代碼移至活動服務器上,問題消失...