title: Dropzone.js - Display existing files on server
body: <p>I'm currently using dropzone.js v3.10.2 I am having issues displaying my existing files I have already uploaded. I am more than competent with php however I have limited knowledge when it comes to ajax and js</p>
  
  <p>If you could help that would be awesome</p>
  
  <p>Thanks in advance</p>
  
  <p>index.php</p>
  
  <pre><code>    &lt;html&gt;
  
  &lt;head&gt;  
  
  &lt;link href="css/dropzone.css" type="text/css" rel="stylesheet" /&gt;
  
  
  &lt;script src="ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;script src="dropzone.min.js"&gt;&lt;/script&gt;
  
  &lt;script&gt;
  
  Dropzone.options.myDropzone = {
      init: function() {
          thisDropzone = this;
  
          $.get('upload.php', function(data) {
  
  
              $.each(data, function(key,value){
  
                  var mockFile = { name: value.name, size: value.size };
  
                  thisDropzone.options.addedfile.call(thisDropzone, mockFile);
  
                  thisDropzone.options.thumbnail.call(thisDropzone, mockFile, "uploads/"+value.name);
  
              });
  
          });
      }
  };
  &lt;/script&gt;
  
  &lt;/head&gt;
  
  &lt;body&gt;
  
  
  &lt;form action="upload.php" class="dropzone" id="my-dropzone"&gt;&lt;/form&gt;
  
  &lt;/body&gt;
  </code></pre>
  
  <p>upload.php</p>
  
  <pre><code>&lt;?php
  $ds          = DIRECTORY_SEPARATOR; 
  
  $storeFolder = 'uploads';  
  
  if (!empty($_FILES)) {
  
      $tempFile = $_FILES['file']['tmp_name'];         
  
      $targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds; 
  
      $targetFile =  $targetPath. $_FILES['file']['name']; 
  
      move_uploaded_file($tempFile,$targetFile);
  
  } else {                                                           
      $result  = array();
  
      $files = scandir($storeFolder);                 //1
      if ( false!==$files ) {
          foreach ( $files as $file ) {
              if ( '.'!=$file &amp;&amp; '..'!=$file) {       //2
                  $obj['name'] = $file;
                  $obj['size'] = filesize($storeFolder.$ds.$file);
                  $result[] = $obj;
              }
          }
      }
  
      header('Content-type: text/json');              //3
      header('Content-type: application/json');
      echo json_encode($result);
  }
  ?&gt;
  </code></pre>
  
  <p>PS. I know the php is retrieving the data</p>
  
  <p>Thanks in advance </p>
  
  <p>Damian</p>