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 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分