这是我的控制器:
function upload()
{
//init var
$status = "";
$msg = "";
$file = "";
$config = array(
'upload_path' => './uploads/product_images/full/',
'allowed_types' => 'gif|jpg|jpeg|png',
'max_size' => '1024',
'encrypt_name' => true,
'remove_spaces' => true
);
$this->load->library('upload', $config);
if (! $this->upload->do_upload('file'))
{
$status = 'Error';
$msg = $this->upload->display_errors('', '');
}
else
{
$uploaded = $this->upload->data();
$this->load->library('image_lib');
//resize ori image to large image
$config['image_library'] = 'gd2';
$config['source_image'] = './uploads/product_images/full/'.$uploaded['file_name'];
$config['new_image'] = './uploads/product_images/large/'.$uploaded['file_name'];
$config['maintain_ratio'] = true;
$config['width'] = 400;
$config['height'] = 400;
$this->image_lib->initialize($config);
$this->image_lib->resize();
$this->image_lib->clear();
//resize large image to small image
$config['image_library'] = 'gd2';
$config['source_image'] = './uploads/product_images/large/'.$uploaded['file_name'];
$config['new_image'] = './uploads/product_images/small/'.$uploaded['file_name'];
$config['maintain_ratio'] = true;
$config['width'] = 180;
$config['height'] = 200;
$this->image_lib->initialize($config);
$this->image_lib->resize();
$this->image_lib->clear();
//resize large image to thumb image
$config['image_library'] = 'gd2';
$config['source_image'] = './uploads/product_images/small/'.$uploaded['file_name'];
$config['new_image'] = './uploads/product_images/thumb/'.$uploaded['file_name'];
$config['maintain_ratio'] = true;
$config['width'] = 80;
$config['height'] = 80;
$this->image_lib->initialize($config);
$this->image_lib->resize();
$this->image_lib->clear();
$status = "Success";
$msg = "File successfully uploaded";
$file = $uploaded['file_name'];
}
echo json_encode(array('status' => $status, 'msg' => $msg, 'file' => $file));
}
和我的js:
$('#upload-btn').on("click",function(e){
e.preventDefault();
$('.loading').show();
var files = $('#img_list');
var url = 'http://sukukhek.com/admin/products/upload/';
$.ajaxFileUpload
({
url: url,
secureuri: false,
fileElementId: 'file',
dataType: 'json',
success : function (data, status)
{
if(data.status == 'Error')
{
$('#feedback').html('<div class="alert-box alert-error"><a class="close-box">x</a>'+data.msg+'</div><br>');
$('.loading').fadeOut('fast');
}
else
{
$('#feedback').html('<div class="alert-box alert-success"><a class="close-box">x</a>'+data.msg+'</div><br>');
$('#title').val('');
$('#caption').val('');
refresh_files(data.file);
}
}
});
return false;
});
function refresh_files(data)
{
var p = data.split('.'),
id = p[0],
filename = p[0]+'.'+p[1],
path = 'http://sukukhek.com/uploads/product_images/small/';
var photo = 'some long html code';
$('#img_list').append(photo);
}
在localhost上,该代码工作正常,但是当我上传到我的服务器上的public_html,文件上传到上传目录,但回调函数不起作用时,仍然会出现加载div,并且新图像不会显示。
Addtitional info:
当文件上传为空时,它是成功发送数据类型:json的错误消息,但是当选择了文件到上传时,它被上传,但回调函数失败。
更新:
在chrome中的网络选项卡上,如果存在要上传的文件,我会收到此消息。
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
<h4>A PHP Error was encountered</h4>
<p>Severity: Warning</p>
<p>Message: escapeshellarg() has been disabled for security reasons</p>
<p>Filename: libraries/Upload.php</p>
<p>Line Number: 1066</p>
</div>{"status":"Success","msg":"File successfully uploaded","file":"5ea47dfe50826f573b65b63f46190a05.jpg"}
答案 0 :(得分:0)
$(document).ready(function(){
$('#photoimg').live('change', function() {
$("#preview").html('');
$("#preview").html('<img src="loader.gif" alt="Uploading...."/>');
$("#imageform").ajaxForm({
target: '#preview'
}).submit();
});
});