title: Creating and uploading a file in PHP to an FTP server without saving locally
body: <p>I'm having a problem connecting two different processes that I have working.  I've been tasked with pulling data out of a database, creating a file from the data, and then uploading it to an FTP server.  </p>
  
  <p>So far, I have the file being created and downloadable using this code, <code>$out</code> being a string that contains the complete text file:</p>
  
  <pre><code>if ($output == 'file')
  {
      header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
      header("Content-Length: ".strlen($out));
      header("Content-type: application/txt");
      header("Content-Disposition: attachment; filename=".$file_name);
      echo($out);
  }
  </code></pre>
  
  <p>This works when I want to just run the script in a browser and download the file, but I'm looking to instead send it to an FTP server.</p>
  
  <p>I know my connection to the FTP server is working just fine, and I'm correctly navigating to the correct directory, and I've taken files from disk and put them on the FTP using <code>ftp_put()</code>, but I'm looking to take <code>$out</code> and write it directly as a file with <code>$filename</code> as its name on the FTP server.  I may be misreading things, but when I tried <code>ftp_put</code> and <code>ftp_fput</code>, it seemed that they want file locations, not file streams.  Is there a different function I could consider?  </p>