我有一个功能,用户可以使用单个图像字段上传最多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;
}
请帮帮我
答案 0 :(得分:0)
$_FILES['file']['tmp_name'];
将包含临时文件名
服务器上的文件。这只是服务器上的占位符
直到你处理文件
对于getimagesize
,您应输入FILE_NAME_AFTER_UPLOADING(OR)'LOCAL_FILE'。
<强>替换强>
$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($upload_file_path.$file);
<强>与强>
$file = time() . $_FILES['file_name']['name'];
$upload_file_path = $site_path . "public/uploads/temp/";
$filetype = $_REQUEST['filetype'];
move_uploaded_file($_FILES["file"]["tmp_name"],$upload_file_path.$file);
/* get width/height of image */
$get_image_info = getimagesize($upload_file_path.$file);