title: html5 file upload api and laravel
body: <p>I have created a HTML5 drag and drop file upload for my laravel app, however I having some trouble setting the filename, as variable that is available to all my controller.</p>
  
  <p>The process the user takes to upload a file, is they fill out some member information, and on submission of the form, a new step is loaded in via ajax, this step is the HTML5 drag and drop file upload.</p>
  
  <p>The problem is not the file upload, that functionality works fine, my problem is that the upload action (below), </p>
  
  <pre><code>public function action_upload()
  {
      $uploadDir = "public/uploads/";
      $file = Input::get('value');
      $name = Input::get('name');
  
      //Get the mime
      $getMime = explode(".", $name);
      $mime = end($getMime);
  
      //seperate the data out
      $fileData = explode(',', $file);
  
      //Encode it correctly
      $encodedData = str_replace(' ', '+', $fileData[1]);
      $decodedData = base64_decode($encodedData);
  
      //create a random name, will help with not overwriting filesystems.
      $this-&gt;randomName = substr_replace(sha1(microtime(true)), '', 12).'.'.$mime;
  
      if(file_put_contents($uploadDir.$this-&gt;randomName, $decodedData)) {
          echo $this-&gt;randomName.":uploaded successfully";
      } else {
          echo "Something went wrong. Check that the upload is not corrupted";
      }
  }
  </code></pre>
  
  <p>As you can see I am setting a variable <code>randomName</code>, after the ajax/HTML5 upload is complete the following code get called, </p>
  
  <pre><code>public function action_source()
  {
      if(Input::get('step') == "step3") {
          //echo $this-&gt;randomName;
          return json_encode(array('next' =&gt; $this-&gt;data['url']."/project/launch", 'file' =&gt; $this-&gt;randomName));
      }
      return View::make('project.source', $this-&gt;data);
  }
  </code></pre>
  
  <p>However the in the JSON object that is return, <code>file</code> is returned as <code>NULL</code> and I dont understand why, at the start of my class i have <code>public $randomName</code> so I should be able to access it via, <code>$this-&gt;randomName;</code></p>
  
  <p>And the order of the function calls if correct, </p>
  
  <p>action_upload() > action_source()</p>
  
  <p>Why can I not access <code>$randomName</code>?</p>