doufei8691 2017-11-13 04:02 采纳率: 100%
浏览 77

jquery文件上传和调整大小不能在服务器上运行的图像

I am using the following jQuery file upload plugin to upload image files and resize it it is working fine in localhost.

While trying it in server i am receiving error:

["pamela.jpg"]{"jquery-upload-file-error":"Image file could not be found!"}

My code is as follows:

<?php
$output_dir = "../images/img_user/";
if(isset($_FILES["file"]) && !empty($_FILES["file"]))
{
$ret = array();
$error =$_FILES["file"]["error"];
if(!is_array($_FILES["file"]["name"])) //single file
{
$fileName = $_FILES["file"]["name"];
move_uploaded_file($_FILES["file"]["tmp_name"],$output_dir.$fileName);
//img resize
require 'imgclass.php';
$resize_image = new Zebra_Image();
$resize_image->preserve_aspect_ratio = true;
$resize_image->source_path = $output_dir.$fileName;
$ext = trim("$fileName");
$resize_image->target_path = '../images/img_user/'.$ext;
if (!$resize_image->resize(128, 128, ZEBRA_IMAGE_NOT_BOXED, 1))
{
// if there was an error, let's see what the error is about
switch ($resize_image->error) {
case 1:
$custom_error= array();
$custom_error['jquery-upload-file-error']="Image file could not be found!";
echo json_encode($custom_error);
die();
case 2:
$custom_error= array();
$custom_error['jquery-upload-file-error']="Image file is not readable!";
echo json_encode($custom_error);
die();
case 3:
$custom_error= array();
$custom_error['jquery-upload-file-error']="Could not write target file!";
echo json_encode($custom_error);
die();
case 4:
$custom_error= array();
$custom_error['jquery-upload-file-error']="Unsupported image file format!";
echo json_encode($custom_error);
die();
case 5:
$custom_error= array();
$custom_error['jquery-upload-file-error']="Unsupported target file format!";
echo json_encode($custom_error);
die();
case 6:
$custom_error= array();
$custom_error['jquery-upload-file-error']="GD library version does not support target file format!";
echo json_encode($custom_error);
die();
case 7:
$custom_error= array();
$custom_error['jquery-upload-file-error']="GD library is not installed!";
echo json_encode($custom_error);
die();
}//end switch
}//end resize error
//end resize
$ret[]= $fileName;
}
echo json_encode($ret);
}
?>

Seems like it is trying to resize the image before the whole file gets uploaded from local desktop to server. How can we ensure that resizing is done only after the whole file gets uploaded?? Seems like that is the issue as it is working fine in localhost. Help requested from experts.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!