jQuery-File-Upload을 사용하고 최대 이미지 업로드를 1 (단일 이미지 업로드)로 제한하려고합니다.PHP의 백엔드에서 jQuery 파일 업로드시 최대 파일 1 개를 제한하는 방법
나는하지만 단지 클라이언트 측에서 같은 JS에서 드래그 앤 드롭에 여러 이미지 업로드를 차단 한 현재로서는 UploadHandler.php
로 server/php/
에있는 데모 버전 자체에서 예를 들어, PHP 파일을 사용하고 있습니다 전체 증명 솔루션으로 신뢰할 수없는 경우 최대 허용 수를 어떻게 제한 할 수 있는지 알고 싶습니다. 지금까지 요청
당 업로드의 내가 행한 :
<input class="photo file" id="fileupload" name="images" type="file">
을 그리고 JS 부분에 :
$('#fileupload').fileupload({
url: url,
dataType: 'json',
autoUpload: true,
dropZone: $('#fileupload'),
singleFileUploads: false,
}).on('fileuploadadd', function (e, data) {
//Hides error
$('.error').hide().children().text('');
var maxFileUploadAllowed = 1;
var fileCount = data.files.length;
if (fileCount > maxFileUploadAllowed) {
$('.error').fadeIn().children().text("You are allowed to upload only 1 file");
return false;
}
하고 제대로 작동하지만 백엔드에 1 개 파일을 제한하는 것이 필요하다
일부 파고에서 options
에 매개 변수가 있다는 것을 발견했습니다. 'max_number_of_files' => null,
변경하려고 시도했습니다. 1
까지 업로드 한 다음 각 파일 업로드시에도 하나의 파일 업로드시 오류가 발생했습니다. Maximum File limit exceeded
이 파문이있는 if
문은 오류가 발생하는 것으로 나타났습니다.
if (is_int($this->options['max_number_of_files']) &&
($this->count_file_objects() >= $this->options['max_number_of_files']) &&
// Ignore additional chunks of existing files:
!is_file($this->get_upload_path($file->name))) {
$file->error = $this->get_error_message('max_number_of_files');
return false;
}
나는 에코
$this->count_file_objects()
했고, 그것을 실제로 업로드 디렉토리에 허용되는 최대 파일을 반환하는 것으로 나타났습니다.
데모 코드에는 처리기가 없으므로 번호를 제한 할 수 없습니다. 백엔드에 파일 업로드의.
내가 아니오를 제한 할 수있는 방법이 있는지 알고 싶었습니다. 백엔드에서 파일 업로드 중?
사용자가 바이올린 때 문제가있을 것입니다 다음
- 이름 배열
<input class="photo file" id="fileupload" name="images[]" type="file">
- "여러"속성
다음 코드 조각
<input class="photo file" id="fileupload" name="images[]" type="file" multiple>
에 아래 : var maxFileUploadAllowed = 1;
var fileCount = data.files.length;
if (fileCount > maxFileUploadAllowed) {
$('.error').fadeIn().children().text("You are allowed to upload only 1 file");
return false;
}
백엔드에 수표가 없기 때문에.
그리고이 과정 전에 몇 가지가 있었다 :