0

这是我的控制器:

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);
}

在本地主机上,该代码运行良好,但是当我上传到服务器上的 public_html 时,文件上传到上传目录,但回调函数不起作用,加载 div 仍然出现,并且新图像不显示。

附加信息:

When file upload is empty, it is success send error message on datatype : json, but when file-to-upload is selected, it is uploaded, but the callback function fail.

更新:

在 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"}
4

1 回答 1

0

$(文档).ready(函数() {

        $('#photoimg').live('change', function()            { 
                   $("#preview").html('');
            $("#preview").html('<img src="loader.gif" alt="Uploading...."/>');
        $("#imageform").ajaxForm({
                    target: '#preview'
    }).submit();

        });
    }); 
于 2014-01-21T07:57:42.990 回答