2012-02-28 29 views
0

我正在使用uploadify上传PHP 5.3.3和Apache 2.2.16服务器的文件。 *我使用的所有图像文件都很小< 1M上传文件坏了

有趣的是,对于某些图像文件,uploadify工作正常并正确上传图像文件。然而对于其他人而言,仅上传8字节是奇怪的。我不知道为什么上传的文件不完整。

Uploadify以某种方式表示文件已成功上传100%,我也使用onError函数。

如何找出问题的任何帮助将是非常有用的。

Uploadify代码:

$('#change_thumb_file').uploadify({ 
'hideButton' : true, 
'wmode'  : 'transparent', 
'folder'  : VG.PROJECT_ROOT + '/static/apps/vialogues', 
    'uploader' : VG.SITE_STATIC_URL+'uploadify/scripts/uploadify.swf', 
    'script'  : VG.APPS_STATIC_URL+"vialogues/php/uploadify.php", 
    'buttonText' : 'Select an image', 
    'cancelImg' : VG.SITE_STATIC_URL+'uploadify/cancel.png', 
    'auto'  : true, 
    'sizeLimit' : 5242880, 
    'queueID'  : 'fileQueue', 
    'scriptAccess': 'always', 
    'method'  : 'POST', 
    'queueSizeLimit' : 1, 
    'width'  : '100', 
    'height'  : '30', 
    'fileDesc' : 'images', 
    'fileExt'  : '*.jpg;*.jpeg;*.png;*.bmp;*.gif', 
    'wmode'  : 'transparent', 
    'altContent' : '<div id="flash_notice">Flash player version 10.0.0 or above is required to upload a video. Please click the icon below to download Flash player.\ 
      <br /><a href="https://www.adobe.com/go/getflashplayer">\ 
      &nbsp;<img src="' + VG.SITE_STATIC_URL + 'uploadify/get_flash_player.gif" alt="Get Adobe Flash player" width="112" height="33">\ 
      </a>\ 
      </div>', 
    'onComplete' : function (event, queueID, fileObj, response, data){ 
     preview_uri = response.replace(VG.PROJECT_ROOT, ''); 
     $.ajax({ 
      url:VG.SITE_URL + 'vialogues/api/crop_thumbnail', 
      type:'PUT', 
      data: {'img': preview_uri}, 
      success: function(data){ 
       $('#thumb_preview').empty().append('<img src="'+preview_uri+'" />'); 
      }, 
      failure: function() {alert("There was an unexpected error. Please try again."); window.location.reload()}, 
     }); 
     $('#step_two').fadeIn(); 
    },    
    'onError' : function(event, queueID, fileObj, errorObj) { 
       var errMsg = "There was an error uploading ... \n"; 
       errMsg += "Error type: " + errorObj.type + "\n"; 
       errMsg += "Error Info: " + errorObj.info + "\n"; 
       alert(errMsg); 
      } 
}); 

它执行文件上传(uploadify.php)代码:

if (!empty($_FILES)) { 
$tempFile = $_FILES['Filedata']['tmp_name']; 
$targetPath = $_REQUEST['folder'] . '/'; 
$targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name']; 

$fileTypes = str_replace('*.','',$_REQUEST['fileext']); 
$fileTypes = str_replace(';','|',$fileTypes); 
$typesArray = split('\|',$fileTypes); 
$fileParts = pathinfo($_FILES['Filedata']['name']); 

if (in_array($fileParts['extension'],$typesArray)) { 

    $result = move_uploaded_file($tempFile,$targetFile); 
    if ($result) { 
     echo str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile);   
    } 
    else { 
     echo 'Upload Failed'; 
    } 
} else { 
    echo 'Invalid file type.'; 
} 

}

+0

请提供您的问题与一些代码来检查出来,以便我们可以帮助你。问候 – 2012-02-28 21:21:59

+0

包括代码...但我不认为这个问题是与代码。我感觉文件上传正在破裂,我不知道我怎么知道它在哪里。 – user504879 2012-02-28 21:33:41

+1

你的Apache错误日志中有什么?另外,在上传过程中,请检查'/ tmp'的内容(假设您的服务器正在运行Linux),并查看是否有一个PHP临时文件随着您的上传发送而增长。 – Crontab 2012-02-28 21:38:22

回答

0

所以这个问题是发生因权限问题英寸我所做的解决方法是在根目录下创建一个单独的文件夹,并为Apache运行的www-data用户提供明确的权限。不知怎的,move_uploaded_file不会引发任何权限错误。