14

I'm trying to work with the blueimp jquery-file-upload plugin. Seems to be a good uploader, but the documentation is not helpful.

When I work with the downloadable demo script, all is ok. But, when I want to change the upload path, that doesn't work.

I've tried to change, in index.php, the action path, like this :

form id="fileupload" action="../uploads/" method="POST" enctype="multipart/form-data"

and added the folders "files" and "thumbnails" in my "uploads" folder.

The GET call is ok, as I can see in Firebug :

GET http://localhost/alliance_pretests/uploads/ 200 OK -8ms

But when I launch the upload action, the POST answers me (still in Firebug) :

POST http://localhost/alliance_pretests/uploads/ 404 Not Found 44ms

I didn't change anything else. What did I forget ?

Why the GET call sees the folder, but not the POST call ?

Thanks in advance. Best regards.

1
  • how are you using this plugin ? do did you implement the server side or use Node.js version ? you need to update the backend to specify the upload directory Commented Feb 22, 2012 at 16:02

2 Answers 2

21

Although the answer @mugur supplied is correct, looking at the php class supplied with the library the first parameter in the construct method is "options" and by declaring an associative array as follows:

$options = array('upload_dir'=>'upload/directory/of/your/choice', 'upload_url'=>'upload/directory/of/your/choice');

and passing it as the first parameter when instantiating the class:

$upload_handler = new UploadHandler($options);

Will allow you to change the upload directory every time you use the class rather than altering the source code.

Sign up to request clarification or add additional context in comments.

3 Comments

You must add these options to the file where you're instantiating the class, if you're using the example then it's index.php. It'd look something like: error_reporting(E_ALL | E_STRICT); require('UploadHandler.php'); $options = array('upload_dir'=>'upload/directory/of/your/choice', 'upload_url'=>'upload/directory/of/your/choice'); $upload_handler = new UploadHandler($options);
What value should I give upload_url if I want to upload my files outside the www folder?
upload_url is the string returned to client browser to display uploaded image or thumbnail. If you upload outside www folder, therefore not accessible for web server to serve files to browser, the image can't be shown. You can instead redirect to some kind of confirmation message or you can copy those files also to some www folder. That's from my short experience with this package.
18

The form action is not the folder where your upload folder should be. The form action is the script where the data is sent after submitting. (see more here about form actions http://www.w3schools.com/tags/att_form_action.asp)

Try finding a destination folder for uploads or look inside the script for that.

Update: after downloading the library

You should look in server/php/upload.class.php and there you have some variables with the location of the upload folder:

'script_url' => $this->getFullUrl().'/',
'upload_dir' => dirname($_SERVER['SCRIPT_FILENAME']).'/files/',
'upload_url' => $this->getFullUrl().'/files/',

Tou should replace /files/ with your own upload folder.

4 Comments

I understood your explanation, and changed my code.That works fine now. Thanks a lot. But how to declare a folder one level upper, like "../uploads" ? I've tried but it doesn't seem to work (error JSON).
How did you modify it? It should be like 'upload_url' => '../uploads/'
It was not working because I didn't removeed $this : 'upload_url' => $this->'../uploads/' Now it's OK. Thanks a lot !
hey, I am working on adding this plugin to wordpress and need to upload to wp's default uploads folder which in my case (because I'm working in a plugin) is three directories up ... this is where UploadHandler.php is wordpress/wp-content/plugins/photo-uploadr/templates/UploadHandler.php and the uploads dir is here wordpress/wp-content/uploads. I've tried doing this ../../../uploads/ but it just creates a new directory (within the templates directory) three levels deep and puts the file there! I'm confused ... nothing I try works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.