jQuery FileUpload语法错误
jQuery FileUpload syntax error
在 CodeIgniter 中实施 jQuery FileUpload 时,一切似乎都正常,没有 javascript 错误,文件在默认文件夹中创建(chmod'ed 0777),但有两个问题。
1.我无法覆盖包提供的 PHP 处理程序上的默认选项。 这是我正在使用的控制器操作,传递的参数中的 none 实际上是已应用,如果我在 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"}]}
根据这篇文档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);
在 CodeIgniter 中实施 jQuery FileUpload 时,一切似乎都正常,没有 javascript 错误,文件在默认文件夹中创建(chmod'ed 0777),但有两个问题。
1.我无法覆盖包提供的 PHP 处理程序上的默认选项。 这是我正在使用的控制器操作,传递的参数中的 none 实际上是已应用,如果我在 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"}]}
根据这篇文档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);