使用jQuery-File-Upload上传文件后如何做“某事”

时间:2013-11-30 00:49:13

标签: jquery jquery-file-upload

我正在使用此代码:(https://github.com/blueimp/jQuery-File-Upload

error_reporting(E_ALL | E_STRICT);
require('UploadHandler.php');

$option = array(
    'upload_dir' => 'myurl',
    'SesId' => 1
);

$upload_handler = new UploadHandler($option);

脚本运行正常,但我希望在文件上传后执行某些操作:

error_reporting(E_ALL | E_STRICT);
require('UploadHandler.php');

$option = array(
    'upload_dir' => 'myurl',
    'SesId' => 1
);

class CustomUploadHandler extends UploadHandler {
    protected function handle_form_data($file, $index) {
        $file->SesId = $this->options['SesId'];     
    }

    protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index=null, $content_range=null) {
        $file = parent::handle_file_upload(
            $uploaded_file, $name, $size, $type, $error, $index, $content_range
        );

        if (empty($file->error)) {
        die();      
        }
        return $file;
    }
}

$upload_handler = new UploadHandler($option);

文件上传很好,但永远不会死()???

我错过了什么?

1 个答案:

答案 0 :(得分:0)

问题是:我调用了错误的实例。

最后一行应该是:

$upload_handler = new CustomUploadHandler($option);