2013-04-29 6 views
1

"파인 업 로더"를 내 CMS에 통합하려고합니다. 업로드가 성공적으로 끝나면 업 로더를 삭제하고 그 외의 삭제 버튼이있는 파일에 대한 링크를 표시합니다. 문제는 마지막 업로드 이후의 시간 간격이 너무 짧아서 (~ 30 초 미만) 모든 업로드가 실패한다는 것입니다. 이 문제는 웹 서버에서만 발생하며 현지 서버에서는 발생하지 않습니다.파인 업 로더 : 파일이 비어 있습니다.

uploader = $('.file-uploader').fineUploader({ 
    request: { 
     endpoint: fullpath+'/detailseite/upload/tmp' 
    }, 
    validation: { 
     allowedExtensions: extensions 
    }, 
    retry: { 
     enableAuto: true 
    }, 
    text: { 
     uploadButton: '<div class="btn button-white">File hochladen</div>' 
    }, 
    multiple: false 
}).on('progress', function (id, fileName, uploadedBytes, totalBytes) { 
    $('.new_elements:not(.disabled),.update_elements:not(.disabled)').addClass('disabled'); 

}).on('complete', function(event, id, fileName, responseJSON) { 
    if (responseJSON.success){ 
     //uploader.fineUploader('reset'); 
     file_name = responseJSON.name; 
     $('.file-uploader').html('<a target="_blank" href="<?php echo PATH; ?>files/tmp/'+file_name+'" ><b>'+file_name+'</b></a><input type="hidden" name="name" value="'+file_name+'" />'); 
     $('.file-uploader').append('<a href="<?php echo $full_path; ?>/contentmanagement/file_loeschen/tmp/'+file_name+'/dokument" class="delete_imageu"></a>'); 
     $('.new_elements,.update_elements').removeClass('disabled'); 
    } 
}); 

$(document).off('click','.'+element_id+' a.delete_imageu'); 
$(document).on('click','.'+element_id+' a.delete_imageu', function() 
{ 
    var url = $(this).attr('href'); 
    $.ajax({ 
     type: "POST", 
     url: url, 
     success: function() { 
      $('.'+element_id).children().remove(); 
      $('.'+element_id).html('<div class="file-uploader" id="<?php echo $element_id; ?>"></div>'); 
      name = element_id; 
      //uploader.fineUploader('reset'); 
      uploader = $('.'+element_id+' .file-uploader').fineUploader({ 
       request: { 
        endpoint: fullpath+'/detailseite/upload/tmp' 
       }, 
       validation: { 
        allowedExtensions: extensions 
       }, 
       retry: { 
        enableAuto: true 
       }, 
       text: { 
        uploadButton: '<div class="btn button-white">File hochladen</div>' 
       }, 
       debug: true, 
       multiple: false 
      }).on('progress', function (id, fileName, uploadedBytes, totalBytes) { 
       $('.new_elements:not(.disabled),.update_elements:not(.disabled)').addClass('disabled'); 

      }).on('complete', function(event, id, fileName, responseJSON){ 
       if (responseJSON.success){ 
        file_name = responseJSON.name; 
        $(this).html('<a target="_blank" href="<?php echo PATH; ?>files/tmp/'+file_name+'" ><b>'+file_name+'</b></a><input type="hidden" name="name" value="'+file_name+'" />'); 
        $(this).append('<a href="<?php echo $full_path; ?>/contentmanagement/file_loeschen/tmp/'+file_name+'/dokument" class="delete_imageu"></a>'); 
        $('.new_elements,.update_elements').removeClass('disabled'); 
       } 
      }); 
     } 
    }); 
    return false; 
}); 

디버그 출력 : 당신은 몇 가지가 발생하는 것처럼

[FineUploader] Processing 1 files or inputs... jquery.fineuploader-3.5.0.min.js:4 
[FineUploader] Sending upload request for 1 jquery.fineuploader-3.5.0.min.js:4 
[FineUploader] xhr - server response received for 1 jquery.fineuploader-3.5.0.min.js:4 
[FineUploader] responseText = {"error":"File is empty"} jquery.fineuploader-3.5.0.min.js:4 
[FineUploader] Waiting 5 seconds before retrying zztailtoddle_lo.mp3... jquery.fineuploader-3.5.0.min.js:4 
[FineUploader] Retrying zztailtoddle_lo.mp3... jquery.fineuploader-3.5.0.min.js:4 
[FineUploader] Sending upload request for 1 jquery.fineuploader-3.5.0.min.js:4 
[FineUploader] xhr - server response received for 1 jquery.fineuploader-3.5.0.min.js:4 
[FineUploader] responseText = {"success":true,"name":"zztailtoddle_lo38.mp3","type":"mp3"} 

서버 측 코드는 코멘트 섹션에서 논의를 바탕으로

class qqFileUploader { 
private $allowedExtensions = array(); 
private $sizeLimit = 10485760; 
private $file; 

function __construct(array $allowedExtensions = array(), $sizeLimit = 10485760){ 
    $allowedExtensions = array_map("strtolower", $allowedExtensions); 

    $this->allowedExtensions = $allowedExtensions; 
    $this->sizeLimit = $sizeLimit; 

    $this->checkServerSettings(); 

    if (isset($_GET['qqfile'])) { 
     $this->file = new qqUploadedFileXhr(); 
    } elseif (isset($_FILES['qqfile'])) { 
     $this->file = new qqUploadedFileForm(); 
    } else { 
     $this->file = false; 
    } 
} 

private function checkServerSettings(){ 
    $postSize = $this->toBytes(ini_get('post_max_size')); 
    $uploadSize = $this->toBytes(ini_get('upload_max_filesize')); 

    if ($postSize < $this->sizeLimit || $uploadSize < $this->sizeLimit){ 
     $size = max(1, $this->sizeLimit/1024/1024) . 'M'; 
     die("{'error':'increase post_max_size and upload_max_filesize to $size'}"); 
    } 
} 

private function toBytes($str){ 
    $val = trim($str); 
    $last = strtolower($str[strlen($str)-1]); 
    switch($last) { 
     case 'g': $val *= 1024; 
     case 'm': $val *= 1024; 
     case 'k': $val *= 1024; 
    } 
    return $val; 
} 

/** 
* Returns array('success'=>true) or array('error'=>'error message') 
*/ 
function handleUpload($uploadDirectory, $replaceOldFile = false,$thumbnail = false,$width = null,$height = null){ 

    if (!$this->file){ 
     return array('error' => 'No files were uploaded.'); 
    } 

    $size = $this->file->getSize(); 

    if ($size == 0) { 
     return array('error' => 'File is empty'); 
    } 

    if ($size > $this->sizeLimit) { 
     return array('error' => 'File is too large'); 
    } 

    $pathinfo = pathinfo($this->file->getName()); 
    $filename = normalize_string($pathinfo['filename']); 

    $ext = $pathinfo['extension']; 

    if($this->allowedExtensions && !in_array(strtolower($ext), $this->allowedExtensions)){ 
     $these = implode(', ', $this->allowedExtensions); 
     return array('error' => 'File has an invalid extension, it should be one of '. $these . '.'); 
    } 

    if(!$replaceOldFile){ 
     /// don't overwrite previous files that were uploaded 
     while (file_exists($uploadDirectory . $filename . '.' . $ext)) { 
      $filename .= rand(10, 99); 
     } 
    } 

     if ($this->file->save($uploadDirectory.$filename.'.'.$ext)){ 

     $src = $uploadDirectory.$filename.'.' . $ext; 


     return array('success'=> true,'name' => $filename. '.' .$ext,'type' => $ext); 
    } else { 
     return array('error'=> 'Could not save uploaded file.' . 
      'The upload was cancelled, or server error encountered'); 
    } 

} 

}

+0

업로드가 성공한 파일과 실패한 파일 (예 : 파일 크기, 파일 형식 또는 파일 이름)간에 체계적인 차이가 있습니까? – Abrixas2

+0

아니요. – Andri

+0

그러면 스크립트와 업로드 된 파일을 처리하는 서버 측 스크립트의 일부로 생성 된 디버그 출력을 게시 할 수 있습니까? 감사. – Abrixas2

답변

1

, 그것은 보인다 서버 쪽에서 문제가 발생합니다. 아마도 뭔가가 요청을 방해하고 있습니까? 내 직장에서도 비슷한 문제가 발생했습니다. 네트워크 어플라이언스가 요청에서 파일을 제거하는 중이었습니다 (또는 그 이상이더라도 기억하지 않습니다). 파일은 자동 재 시도에 성공할 것이다. 나는 또한 PHP 요청 처리기에서 무언가가 올바르지 않을 수도 있다고 생각합니다. 당신은 좀 더 깊게 파고들 필요가있을 것입니다. 이것은 PHP 처리기에 부딪 힐 때 요청을 검사하고 Chrome/Firebug의 네트워크 탭이나 프록시 (예 : Charles)에 따라 요청과 비교하는 작업을 포함 할 수 있습니다. 요청이 일치하지 않으면 요청한 항목을 가로 채서 방해합니다. 그것들이 일치하고 요청이 정상적으로 보인다면 아마도 PHP 코드에 문제가있을 것입니다.

+0

아아, 이제 아주 흥미로운 걸 발견했습니다! 단일 업로드 사이의 시간입니다. 각 업로드 후 30 초 기다렸다가 오류가 발생하지 않습니다. 무엇이 이것을 일으킬 수 있습니까? – Andri

+0

서버 측 문제 –

+0

... 서버 구성 오류입니까? – Andri

관련 문제