2017-07-03 112 views
0

我試圖通過api上傳文件到vshare.io。啓動時,它會爲約1分鐘運行腳本,然後將打印PHP - 上傳腳本中的神祕錯誤

<?php 
if(!function_exists('curl_init')) { 
    die('CURL functions are not available. Debian: apt-get install php5-curl'); 
} 

$file_path = ''; // Example: $file_path = '/home/files/file.exe'; 
$token = ''; // You can get your TOKEN from the following page http://vshare.io/api.html 
$post = array(
    'token' => $token, 
    'filesize' => filesize($file_path), 
    'Filedata' => '@' . $file_path 
); 
// init 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, 'http://upload.vshare.io/upload_api.php'); 
curl_setopt($ch, CURLOPT_POST, TRUE); 
curl_setopt($ch, CURLOPT_HEADER, FALSE); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Expect: ")); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); 
$result = curl_exec($ch); 
curl_close($ch); 
$output = json_decode($result, TRUE); 
if(isset($output['upload'], $output['video'], $output['fileid']) && strlen($output['fileid']) == 7 && $output['upload'] == 1) { 
    if($output['video'] == '1') { 
     $file_type = 'video'; 
    } elseif($output['video'] == '0') { 
     $file_type = 'file'; 
    } 
    echo 'File Type: ' . $file_type . ' | File Link: http://vshare.io/d/' . $output['fileid']; 
} else { 
    echo 'Error: ' . $output['msg']; 
} 
?> 

我插入我的令牌,並在Ubuntu正確的文件路徑,但是:他們提供一個PHP腳本這樣做的「錯誤」 (腳本的最後一行說這樣做)。沒有文件上傳到我的帳戶

任何提示?

回答

0

可能有2個原因。首先是你的用戶代理,你還沒有設置它。最網站今天限制BOT所以你應該將它設置爲您捲曲:

curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17');

的第二個原因是,捲曲處理時間,所以你什麼都沒有,也沒有任何消息。

試一下這個

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,0); 
curl_setopt($ch, CURLOPT_TIMEOUT, 400); 
+0

添加既劇本,但得到相同的輸出:(這可能是因爲這個\t \t \t \t $結果= curl_exec($ CH);我注意到,有curl_close命令,但執行被封裝在$ result中 – user3919889

+0

您是否嘗試轉儲$ result,您收到了什麼?NULL消息? –

+0

如果我這樣做,腳本將永遠阻止永遠(lol)。 ,我必須退出CTRL + Z – user3919889