How do I change the default upload path for jquery file upload

送分小仙女□ 提交于 2019-12-04 08:41:54

You can do it in two ways: 1.. by changing the line 40 in server / php / UploadHandler.php and put the directory you want

 'upload_dir' => dirname($this->get_server_var('SCRIPT_FILENAME')).'/files/',

2.. by adding the upload dir as parameter when initializing the class

$options = array ('upload_dir' => dirname(__FILE__) . '/uploaddir/');
$upload_handler = new UploadHandler($options);

Add these options to your UploadHandler() function. Make sure to add "/" to end of path.

$upload_handler = new UploadHandler(array(
            'upload_dir' => '/Your/absolute/upload/folder/path/',  
            'upload_url' => '/url/of/above/path/',
            'script_url' => '/url/of/uploadhandler/script',
            'accept_file_types' => '/\.(jpe?g|png)$/i'
     ));

I found by changing the path located in UploadHandeler.php on lines 40 and 41 this changed the specified path.

You can override the callback function as per

$('#fileupload').fileupload({
add: function (e, data) {
    var jqXHR = data.submit()
        .success(function (result, textStatus, jqXHR) {/* ... */})
        .error(function (jqXHR, textStatus, errorThrown) {/* ... */})
        .complete(function (result, textStatus, jqXHR) {/* ... */});
}
});

In the above example it is simply doing a form submit.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!