title: Pass image data from form upload to a function to save
body: <p>I have an upload form with mulitple file attachments name="attachment[]"</p>
  
  <p>I need to pass the uploaded file to a function in a class which handles the saving of the file (amongst other actions).</p>
  
  <p>The function:</p>
  
  <pre><code>public function saveFile($userId, $ticketId, $fileType, $fileName, $fileContent) 
  {
      // Create directory
      $this-&gt;createDirectory($ticketId);
  
      $file = fopen(FILE_SAVE_PATH . "/" . $ticketId . "/" . $fileName, 'w');
      fwrite($file, $fileContent);
      fclose($file);
  }
  </code></pre>
  
  <p>The loop which is sending the function the data</p>
  
  <pre><code>foreach($_FILES['attachment']['name'] as $index =&gt; $value) 
  {
        $fw-&gt;models-&gt;file-&gt;saveFile(
                              $si-&gt;input-&gt;session('bug/userData/id'), 
                              $ticketId, 
                              '', 
                              $_FILES['attachment']['name'][$index],
                              base64_encode($_FILES['attachment']['tmp_name'][$index]));
  }
  </code></pre>
  
  <p>As you can see I've tried base64_encode, the image is "saved" but it is corrupt when i try open it.</p>
  
  <p>Thank you.</p>