我有一项功能,用户可以使用单个图像字段上传最多 48 张照片。
现在,当我一次上传 48 张图像时,我正在做的是调用 ajax 函数。Ajax 调用将使用 PHP 的 getimagesize 函数检查图像的宽度和高度。
有时会发生什么情况,如果我选择上传 48 张图片,那么在上传 20-25 张图片后,getimagesize 函数返回 false 而不是包含大小、宽度、高度等的数组...
JS代码
$('#multi_file_upload').change(function(e){
var file_id = e.target.id;
var form_data = new FormData();
var file_name_arr = new Array();
var process_path=site_url+'public/uploads/';
for(i=0;i<$("#"+file_id).prop("files").length;i++){
/* check whether remaining count reaches 0 */
var file_data = $("#"+file_id).prop("files")[i];
form_data.append("file_name", file_data);
$("#sortable-new li").each(function(n, element){
var tid = $(this).children('div').attr('id');
if($.trim( $("#"+tid).html() ).length == 0) {
html_div = tid;
return false;
}
});
if($.trim( $("#"+html_div).html() ).length == 0) {
$("#"+html_div).parents('li').removeClass('additional-photo ui-state-disabled');
$("#"+html_div).html('<img src="<?php echo $site_image_url;?>ajax-loader-showcase.gif" />');
if(check_multifile_logo($("#"+file_id).prop("files")[i]['name'])){
$.ajax({
//url : site_url + "inc/upload_image.php?width=96&height=60&show_small=1",
url : site_url + "inc/upload_contact_info.php?width=<?php echo $assoc_width?>&height=<?php echo $assoc_height?>&filetype=multiple_file_upload",
cache : false,
contentType : false,
processData : false,
async:false,
data : form_data,
type : 'post',
success : function(data) {
if(data != '') {
if(data==1){
alert("Image should not be smaller than <?php echo $assoc_width?> pixels wide by <?php echo $assoc_height?> pixels high.");
$("#"+html_div).html('');
//$("#"+html_div).parents('li').addClass('additional-photo ui-state-disabled');
} else {
remaining_cnt--;
multifile_cnt++;
if(multifile_cnt > 29) {
$(".galleryBox").css('min-height','845px');
$('.additional-photo').show();
}
$("#"+html_div).parents('li').addClass('ui-state-highlight');
$("#"+html_div).css('background-color', '#2B1F19');
//$("#"+html_div).html('<img src="'+process_path +'96x60-' +data+'" width="96" height="60" />');
$("#"+html_div).html('<img src="'+ process_path +data+'" width="102" height="68" class="crop-image">');
$('#'+html_div).append('<img src="<?php echo $site_url;?>public/uploadify/uploadify-cancel.png" class="cancel_multiple_file" >');
setTimeout(function(){$("#"+html_div).css('background-color', 'transparent');},2000);
$('#btn_btop').fadeIn();
}
} else {
alert(data);
}
}
});
} else {
$("#"+html_div).html('');
alert('We only accept JPG, JPEG, PNG, GIF and BMP files');
}
}
}
});
PHP 代码(ajax 调用)
$file = time() . $_FILES['file_name']['name'];
$upload_file_path = $site_path . "public/uploads/temp/";
$filetype = $_REQUEST['filetype'];
/* get width/height of image */
$get_image_info = getimagesize($_FILES['file_name']["tmp_name"]);
$image_width = $get_image_info[0];
$image_height = $get_image_info[1];
/* get required width/height */
$width = mysql_real_escape_string($_REQUEST['width'], $CON);
$height = mysql_real_escape_string($_REQUEST['height'], $CON);
$method = mysql_real_escape_string($_REQUEST['method'], $CON);
$show_small = isset($_REQUEST['show_small']) ? mysql_real_escape_string($_REQUEST['show_small'], $CON) : '0';
if ($image_width < $width || $image_height < $height) {
echo 1;
exit;
}
请帮帮我