dongqian1925 2015-05-13 11:34
浏览 68
已采纳

jQuery FileUpload语法错误

While implementing jQuery FileUpload in CodeIgniter everything seems to work, no javascript errors and the files get created in the default folders (chmod'ed 0777), but there are two issues.

1. I can't override the default options on the PHP handler provided by the package. Here is the Controller action I'm using to do so, none of the parameters passed are actually applied, if I dump the options within the UploadHandler I get the default options.

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. The script is throwing a error when a file finishes uploading :

SyntaxError: Unexpected token {

Here is the response of an example request :

{"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条回答 默认 最新

  • doushang1964 2015-05-13 12:01
    关注

    According to this document Creating Libraries check how we can pass the param in library

    so it would be:-

     $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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含