PHP-上传脚本中的神秘错误
我正试图通过他们的api将一个文件上传到vshare.io。他们提供了一个php脚本:PHP-上传脚本中的神秘错误,php,linux,upload,Php,Linux,Upload,我正试图通过他们的api将一个文件上传到vshare.io。他们提供了一个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 = '';
<?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中插入了我的令牌和正确的文件路径,但是当启动脚本时,它将运行大约1分钟,然后它将打印“Error:”(脚本的最后一行说这样做)。没有文件上载到我的帐户
有什么提示吗?可能有两个原因。首先是您的用户代理,您还没有设置它。目前最受限制的站点是BOT,因此您应该为CURL设置它:
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0(windowsnt 6.1;WOW64)AppleWebKit/537.17(KHTML,像Gecko)Chrome/24.0.1312.52 Safari/537.17')代码>
第二个原因是CURL进程超时,因此您没有收到任何消息
试试这个
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,0);
curl_setopt($ch, CURLOPT_TIMEOUT, 400);
可能有两个原因。首先是您的用户代理,您还没有设置它。目前最受限制的站点是BOT,因此您应该为CURL设置它:
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0(windowsnt 6.1;WOW64)AppleWebKit/537.17(KHTML,像Gecko)Chrome/24.0.1312.52 Safari/537.17')代码>
第二个原因是CURL进程超时,因此您没有收到任何消息
试试这个
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,0);
curl_setopt($ch, CURLOPT_TIMEOUT, 400);
将两者都添加到脚本中,但收到相同的输出:(可能是因为这个?$result=curl\u exec($ch);我注意到有curl_close命令,但execute在$result中被封装。您是否尝试转储$result,您收到了什么?空消息?如果我这样做,脚本将永远阻塞(lol)。根本没有输出,我必须使用CTRL+Zit退出。服务器中可能禁用了curl\u exec函数,因此如果这有助于将两者添加到脚本中,请检查php错误日志,但收到相同的输出:(可能是因为这个?$result=curl\u exec($ch);我注意到有curl_close命令,但execute在$result中被封装。您是否尝试转储$result,您收到了什么?空消息?如果我这样做,脚本将永远阻塞(lol)。根本没有输出,我必须使用CTRL+Zit退出。服务器中禁用了exec函数,因此请检查php错误日志(如果有帮助)