我在我的网站上设置了Uploadify jQuery插件来管理文件上传。在onUploadSuccess
事件中,我有以下代码:
'onUploadSuccess' : function(file, data, response) {
console.log("Upload complete for file " + file.name + ". Script returned: " + data);
}
这是为了向我展示上传脚本吐出的任何内容。现在,通常响应是这样的:
上传完成文件测试.jpg。返回的脚本: {"status":1,"file":{"id":"v8rwlxj3","name":"test.jpg"}}
上传脚本首先接受文件,然后使用 cURL 将其上传到 Rapidshare,如下所示:
// Move uploaded file
move_uploaded_file($_FILES['Filedata']['tmp_name'], $targetDir . '/' . $id);
// Get the RapidShare server to upload to
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://api.rapidshare.com/cgi-bin/rsapi.cgi?sub=nextuploadserver');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if(!$uploadServer = trim(curl_exec($ch))) {
error('nextuploadserver failed');
}
if(strstr($uploadServer, 'ERROR:')) {
error('nextuploadserver failed');
}
// Upload the file to RapidShare
$uploadID = mt_rand(1000000000, 9999999999);
$url = 'http://rs' . $uploadServer . '.rapidshare.com/cgi-bin/rsapi.cgi?uploadid=' . $uploadID;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
$postFields = array('sub' => 'upload',
'login' => 'login',
'password' => 'password',
'uploadid' => $uploadID,
'filename' => $_FILES['Filedata']['name'],
'filecontent' => '@' . $targetDir . '/' . $id);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
if(!$resp = curl_exec($ch)) {
error('upload call failed');
}
上传时,上传脚本会吐出一个 JSON 响应,如下所示:
// Output
echo json_encode(array('status' => 1, 'file' => array('id' => $id, 'name' => $uploadDetails[1])));
这适用于较小的文件。但是,当我上传30MB的测试文件时,我得到以下响应:
上传完成文件 30mb.txt。返回的脚本:
起初我以为 PHP 达到了最大执行时间,但我在脚本的顶部有这个:
set_time_limit(21600); // 6 hours
此外,我会看到返回的PHP错误。但它只是没有返回任何东西。什么原因可能导致这种情况?谢谢。
您确定您的upload_max_filesize设置为 30M 以上吗?过去,那个让我有些头疼。
PHP 可能没有达到时间限制,但 ajax 可能在等待响应时达到连接超时。
删除上传 id 发布参数。带有简历上传的上传 id 参数。
是的,很好的答案,虽然它在评论中,但帮助了我。http://www.uploadify.com/documentation/uploadify/successtimeout/
将成功超时设置为某个高值。假设 1 小时。