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

I have implemented the jQuery file upload plugin with a php framework it was relatively straight forward following the instructions.

https://github.com/blueimp/jQuery-File-Upload

My question is specifically towards the PHP class, When the images upload they upload into my framework folder (where the php script is executed). What I want to know is if there is a way to set the path where images will be uploaded to.

This is the class in question.

https://github.com/blueimp/jQuery-File-Upload/blob/master/server/php/UploadHandler.php

It is included in the jQuery file upload repository.

Answers


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.


Need Your Help

"JSSOR touch and swipe" in windows 8 not working

internet-explorer jssor

I am using the jssor slider library which works perfectly fine in all devices (touch and non-touch) but fails miserably with windows8.1 touch screen kiosk machine (IE11). Even the demo links they h...

Windows Service exception using NLog to write to file on Windows Server 2008 R2

c# security windows-services windows-server-2008-r2 nlog

I'm running into a debug logging issue with NLog, .NET 4.0.3 and Windows Server 2008 R2 (x64).