dongpei3245 2012-02-28 21:18
浏览 61
已采纳

上传文件已损坏

I am using uploadify for uploading the files with PHP 5.3.3 and Apache 2.2.16 server. *All the image files I am using are small < 1M

Interestingly for some of the image files uploadify works fine and uploads the image file correctly. However for others only 8bytes are uploaded which is weird. I am not sure why the uploaded file is not complete.

Uploadify somehow says the file is 100% successfully uploaded and I am using the onError function too.

Any help in how to find out the problem would be really helpful.

Uploadify code:

$('#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 ... 
";
              errMsg += "Error type: " + errorObj.type + "
";
              errMsg += "Error Info: " + errorObj.info + "
";
              alert(errMsg);
            }
});

The code which does the file upload (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.';
}

}

  • 写回答

1条回答 默认 最新

  • doushu8260 2012-03-09 22:01
    关注

    So the issue was happening in because of permissions problem. The workaround I did was to create a separate folder in the root directory and giving it explicit permissions to the www-data user under which apache runs. Somehow move_uploaded_file wasn't throwing any errors for permission.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的