2013-01-06 192 views
0

我想將文件從一個網站轉移到使用POST服務器上傳文件到遠程服務器使用PHP捲曲

我的代碼,這個網站gulfup.com(它含有沒有文件上傳的問題):

<?php 

$the_file = "http://downloads.wordpress.org/plugin/wp-super-cache.1.2.zip"; 

$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_HTTPHEADER, array("Content-type: multipart/form-data")); 
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; Linux i686; rv:6.0) Gecko/20100101 Firefox/6.0Mozilla/4.0 (compatible;)"); 
curl_setopt($ch, CURLOPT_URL, 'http://www.gulfup.com/index.php'); 
curl_setopt($ch, CURLOPT_POST, true); 
$post = array(
    'file_1_' => "$the_file" 
); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
$response = curl_exec($ch); 
if(curl_errno($ch)) { 
    echo 'Error: ' . curl_error($ch); 
} 
else { 
    echo $response; 
} 

?> 

網站代碼從PC上傳:

<form id="uploader" name="uploader" action="http://www.gulfup.com/index.php" method="post" enctype="multipart/form-data" onsubmit="form_submit();"> 
<div class="uploadfile"><input name="file_1_" id="file_1_" size="70" type="file"></div> 
<br id="br_1_"> 
<div class="uploadfile"><input name="file_2_" id="file_2_" size="70" type="file"></div> 
<br id="br_2_"> 
<div class="uploadfile"><input name="file_3_" id="file_3_" size="70" type="file"></div> 
<br id="br_3_"> 
<div class="uploadfile"><input name="file_4_" id="file_4_" size="70" type="file"></div> 
<br id="br_4_"> 
<div class="uploadfile"><input name="file_5_" id="file_5_" size="70" type="file"></div> 
<br id="br_5_"> 
<div class="uploadfile"><input name="file_6_" id="file_6_" size="70" type="file"></div> 
<br id="br_6_"> 
<div class="uploadfile"><input name="file_7_" id="file_7_" size="70" type="file"></div> 
<br id="br_7_"> 
<div class="uploadfile"><input name="file_8_" id="file_8_" size="70" type="file"></div> 
<br id="br_8_"> 
<div class="uploadfile"><input name="file_9_" id="file_9_" size="70" type="file"></div> 
<br id="br_9_"> 
<div class="uploadfile"><input name="file_10_" id="file_10_" size="70" type="file"></div> 
<br id="br_10_"> 
<br> 

<span class="bn_up"><button type="submit" name="submitr" class="btn" id="submitr"><span>Upload</span></button></span> 

<div class="clr"></div> 
</form> 

什麼是我的代碼的問題?

+0

第一線

$the_file = "http://downloads.wordpress.org/plugin/wp-super-cache.1.2.zip"; 

什麼是彈出的錯誤忘了@(人品)當你運行這個腳本?請指定 –

+0

您確定是否需要進行文件上傳驗證? –

+3

看起來你只是將URL發送到文件,而不是文件本身。 –

回答

-1
+0

我不知道它的工作與否..但它不顯示新鏈接的頁面不出現只是一個空白頁:( – user1763141

+0

我想你會發現「@」符號只是佔位符的一部分在這篇文章中使用的文本,真正的問題是用戶沒有發送本地文件的文件名(按照你引用的文章),而是發送一個遠程文件的URL。 –

+0

你的意思是說腳本應該首先下載文件,然後再上傳一次?我如何將文件從我的網站發送到另一個上傳網站? – user1763141

-1

嘗試編輯以

$the_file = fetch_remote_file("http://downloads.wordpress.org/plugin/wp-super-cache.1.2.zip"); 
+0

'fetch_remote_file()'不是一個標準的PHP函數。 –

+0

Lucanos是正確的.. fetch_remote_file()不是一個標準的PHP函數 – user1763141

+0

是的我知道,但你可以谷歌那個功能:) – Joe

相關問題