3

how can i change the upload directory?

i want to change the file upload directory dynamically

f.g : for each user,upload files to her/his folder

thanks

2 Answers 2

4

You can store the directory in a $_SESSION variable or in a $_COOKIE , and then get the saved value in the file /php/index.php

$uplDir = $_SESSION["uploadDirectory"].'/;

$option = array(
    /* some options */
    'upload_dir' => $uplDir,

    /* .... */
);
$upload_handler = new UploadHandler($option);

ps. remember the session_start(); at the beginning

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

1 Comment

I am sure it would be better to store it in session. Session can not be manipulated on the client side, so one can not change the path to something dangerous.
4

You can send that via parameters in the form data in js file

 <script>
    $(function () {
     $('#fileupload').fileupload({
     dataType: 'json',
     formData: [{ name: 'custom_dir', value: '/save/file/here/' }],
     done: function (e, data) {
     $.each(data.result.files, function (index, file) {
     $('<p/>').text(file.name).appendTo(document.body);
     });
     }
     });
    });
 </script>
   //=========================

while in the upload handler definition

    require('UploadHandler.php');
    $custom_dir = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['custom_dir'];
    $upload_handler = new UploadHandler(array('upload_dir' => $custom_dir));

1 Comment

Very nice, exactly what I was looking for!

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.