title: Moving a photo uploaded with Dropzone.js and PHP
body: <p>I'm trying to use <a href="http://www.dropzonejs.com/" rel="nofollow noreferrer">dropzone.js</a> to add an easy drag-and-drop interface for a user to upload up to 10 photos to my server (currently WAMP). I'm using PHP 5.4 on the back end.</p>
  <p>Following <a href="http://www.startutorial.com/articles/view/how-to-build-a-file-upload-form-using-dropzonejs-and-php" rel="nofollow noreferrer">this tutorial</a> I got the system working enough to upload acceptable file types to an 'Uploads' folder in my root directory, but I'm stuck on how to make the photos instead upload to a unique directory for each user.</p>
  <p>By the time the user gets to my photo upload page, they've already created a folder on my server with a unique name, the path to which has been stored in $_SESSION['requestedDirectory'].</p>
  <p>Here is the code used to display the Dropzone form:</p>
  <pre><code>&lt;form action=&quot;&lt;?php echo BASE_URL; ?&gt;photo_uploads.php&quot; class=&quot;dropzone&quot; id=&quot;photoUploadDropzone&quot;&gt;&lt;/form&gt;
  
  &lt;script type=&quot;text/javascript&quot;&gt;
      Dropzone.options.photoUploadDropzone = {
        paramName: &quot;file&quot;,
        maxFilesize: 5, // MB
        maxFiles: 10,
        addRemoveLinks: true,
        acceptedFiles: &quot;image/jpeg, image/jpg, image/png, image/gif&quot;,
        accept: function(file, done) {
          done();
        }
      };
  &lt;/script&gt;
  </code></pre>
  <p>As you can see, it sends the data to a file called photo_uploads.php, which has the following code:</p>
  <pre><code>if (!empty($_FILES)) {
    $tempFile = $_FILES['file']['tmp_name'];
    $targetPath = $_SESSION['requestedDirectory']; &lt;--HERE'S THE PROBLEM LINE
    $targetFile =  $targetPath. $_FILES['file']['name'];
    move_uploaded_file($tempFile,$targetFile);
  }
  </code></pre>
  <p>As mentioned in the comment above, this file doesn't seem to be able to take data out of a session variable, but I'm not sure why. If I change that line to give the full directory (eg $targetPath = 'C://wamp/www/shops/foldername';) it works fine, but then of course I can't change that foldername dynamically based on which user is using the form.</p>
  <p>So to clarify, I'd like to know how to upload the file to the path stored in Session?</p>
  <h1>UPDATE: Solved.</h1>
  <p>For anyone else with the same problem in future, this is what I changed the form to:</p>
  <pre><code>&lt;form action=&quot;&lt;?php echo BASE_URL; ?&gt;photo_uploads.php?folder=&lt;?php echo $_SESSION['photosDir']; ?&gt;&quot; class=&quot;dropzone&quot; id=&quot;photoUploadDropzone&quot;&gt;&lt;/form&gt;
  </code></pre>
  <p>Like Rizwan suggested, by passing the $_SESSION['photosDir'] value in a GET variable it was accessible after the form posted.</p>
  <p>The other change I made was to photo_uploads.php, just to the following line:</p>
  <pre><code>$targetPath = $_GET['folder'];
  </code></pre>
  <p>Absolutely no idea why the value wasn't available directly from Session in the first place - I've never heard of Session values going out of scope - but happy to have this problem solved.</p>