jQuery FileUpload语法错误

时间:2015-05-13 11:34:33

标签: php jquery codeigniter jquery-file-upload

在CodeIgniter中实现jQuery FileUpload时,一切似乎都有效,没有javascript错误,文件在默认文件夹中创建(chmod' ed 0777),但有两个问题。

1。我无法覆盖软件包提供的PHP处理程序的默认选项。这是我用来执行的Controller操作,如果我转储,实际应用的参数都没有UploadHandler中的选项我得到了默认选项。

public function fileupload()
{
    if ($this->input->is_ajax_request())
    {
        # load library
        $this->load->library('UploadHandler');

        # upload file
        $upload_handler = new UploadHandler(array(
            'upload_dir' => FCPATH.'upload/realty/'.$this->_user->id.'/',
            'mkdir_mode' => 0777,
            'accept_file_types' => '/\.(gif|jpe?g|png)$/i',
        ));
    }
    else
    {
        redirect('error/page_not_found');
    }
}

2。文件完成上传后,脚本会抛出错误:

SyntaxError: Unexpected token {

以下是示例请求的响应:

{"files":[{"name":"nebula-ngc-281.jpg","size":590295,"type":"image\/jpeg","url":"http:\/\/test.filipematias.info\/mercadoimobiliario\/admin\/files\/nebula-ngc-281.jpg","thumbnailUrl":"http:\/\/test.filipematias.info\/mercadoimobiliario\/admin\/files\/thumbnail\/nebula-ngc-281.jpg","deleteUrl":"http:\/\/test.filipematias.info\/mercadoimobiliario\/admin\/?file=nebula-ngc-281.jpg","deleteType":"DELETE"}]}{"files":[{"name":"nebula-ngc-281 (1).jpg","size":0,"type":"image\/jpeg","error":"File upload aborted","deleteUrl":"http:\/\/test.filipematias.info\/mercadoimobiliario\/admin\/?file=nebula-ngc-281%20%281%29.jpg","deleteType":"DELETE"}]}

1 个答案:

答案 0 :(得分:1)

根据这份文件Creating Libraries,检查我们如何在库中传递参数

所以它会是: -

 $options= array(
            'upload_dir' => FCPATH.'upload/realty/'.$this->_user->id.'/',
            'mkdir_mode' => 0777,
            'accept_file_types' => '/\.(gif|jpe?g|png)$/i',
        ));
$this->load->library('UploadHandler',$options);