【发布时间】:2014-04-01 10:54:10
【问题描述】:
我一直卡在上传部分。我正在使用uploadify 脚本。正常文件已成功上传,但是当我厌倦了上传带有 file's.jpg 之类的文件名时,会发生 HTTP 500 错误。 我的上传脚本是:
<script type="text/javascript">
// <![CDATA[
$(document).ready(function() {
$('#attachment').uploadify({
'uploader' : '<?php echo base_url();?>web/uploadify/uploadify.swf',
'script' : '<?php echo base_url();?>web/uploadify/uploadify.php',
'cancelImg' : '<?php echo base_url();?>web/uploadify/cancel.png',
//'folder' : '../../uploads/project_files/',
'folder' : '/admin_panel_new/assets/plupload/uploads/',
'auto' : true,
'multi' : true,
'hideButton': false,
'buttonImg' : "<?php echo base_url()?>images/attachment_image.gif",
'width' : 132,
'height' : 25,
'removeCompleted' : false,
'onSelect' : function(file) {
$('#submitFeedback').val('Please wait while uploading...');
$('#submitFeedback').attr('disabled','disabled');
},
'onComplete' : function(event, ID, fileObj, response, data) {
if($('#fileList').val()!='')
$('#fileList').val($('#fileList').val()+','+response);
else
$('#fileList').val(response);
//alert($('#fileList').val());
$('#submitFeedback').removeAttr('disabled');
$('#submitFeedback').val('Post Feedback');
},
'onError' : function(event, queueID, fileObj, errorObj) { alert(errorObj.type + ' ' + errorObj.info ); }
});
});
</script>
我尝试了许多其他解决方案,但都没有运气。
我的uploadify.php代码是:
<?php
$targetFolder = $_POST['targetFolder']; // Relative to the root
$unik =$_POST['timestamp'];
$verifyToken = md5('unique_salt' . $_POST['timestamp']);
if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$targetFile = rtrim($targetPath,'/') . '/'.$unik.'_'.$_FILES['Filedata']['name'];
// Validate the file type
$fileTypes = array('jpg','jpeg','gif','png','txt'); // File extensions
$fileParts = pathinfo($_FILES['Filedata']['name']);
if (in_array($fileParts['extension'],$fileTypes)) {
move_uploaded_file($tempFile,$targetFile);
//
echo $unik.'_'.$_FILES['Filedata']['name'];
} else {
echo 'Invalid file type. Upload Failed';
}
}
?>
上传错误图片如下所示
如果有人有解决方案,请帮忙。谢谢。
【问题讨论】:
-
不,实际上文件只是一个 kb 而不是更大的大小。
-
“500 内部服务器错误”状态码的基本意思是:“请检查日志以了解发生了什么”。你试过吗?只是猜测可能需要很长时间。
-
我已经检查过了,但没有找到任何错误日志。由于相同的代码在 localhost 中像魅力一样工作,但在现场尝试时没有成功。 :(