2014-04-01 122 views
4

我一直卡在上传部分。我正在使用uploadify脚本。正常的文件上传成功,但当我累了上传一个文件的名称,如'file's.jpg然后发生HTTP 500错误。 我uploadify脚本是:使用uploadify上传文件时出现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'; 
    } 
} 
?> 

上传错误图像看起来像这样 enter image description here

如果有人解决方案,请帮助。谢谢。

+0

可能文件大小? – Sal00m

+0

不,实际上文件只是一个kb而不是一个更大的大小。 –

+3

“500内部服务器错误”状态码的基本含义是:“请检查日志以了解发生了什么”。你尝试过吗?猜测可能需要很长时间。 –

回答

0

如果问题只使用单引号文件名时,我会看的第一个地方是

$_FILES['Filedata']['name'] 

既然你串联的转义输入字符串,有一个公平的机会,单引号扔东西用move_uploaded_file关闭。 This thread演示了类似的问题。

我可能只是从文件名中删除单引号,然后再存储它。或者尝试addslashes

$targetFile = rtrim($targetPath,'/') . '/'.$unik.'_'.str_replace("'","",$_FILES['Filedata']['name']); 
+0

感谢您的回答,但同样的错误再次发生,使用您的代码也试图上传一个文件名base's_camp_mail.txt并发生此错误 –

+0

您有权访问服务器的错误日志吗?首先我要查找500个错误,或者尝试用静态字符串替换名称,比如“test.txt”,以查看是否可以将问题与文件名隔离。 –

相关问题