title: File upload code gives this error - Warning: ftp_put(): Filename cannot be empty
body: <p>I'm trying to write code that will allow me to upload an image to the ftp server, but for some reason it throws the error "Warning: ftp_put(): Filename cannot be empty". I've looked around and and none of the solutions I found work, please help!</p>
  
  <p>Here is my form code:</p>
  
  <pre><code>&lt;form id="edit-cd" method="post" enctype="multipart/form-data"&gt;
      &lt;input type="file" name="headliner-logo" /&gt;
      &lt;input type="submit" name="submit-headlogo" class="submit-btn" value="Submit" /&gt;
  &lt;/form&gt;
  &lt;?php
  if (isset($_POST['submit-headlogo'])) {
      if ($_FILES['headliner-logo']['size'] &lt;= 0) {
          error("No file was chosen to upload");
      } else if ($_FILES['headliner-logo']['size'] &gt; 1572864) {
          error("File too large, max. filesize is 1.5mb");
      } else if ($_FILES['headliner-logo']['type'] != "image/png") {
          error("Invalid filetype, .png only");
      } else {
          setHeadlinerLogo($_FILES['headliner-logo']['tmp-name'], $_FILES['headliner-logo']['name']);
      }
  }
  ?&gt;
  </code></pre>
  
  <p>And here is the code that does the uploading:</p>
  
  <pre><code>function setHeadlinerLogo($source, $name) {
      $server = "ftp.server.com";
      $user = "username";
      $pass = "password";
      $dest = "/public_html/directory/img/";
  
      // Set up connection
      $conn = ftp_connect($server);
      if ($conn) {
          // Login
          $login = ftp_login($conn, $user, $pass);
          if($login) {
              // Upload File
              $upload = ftp_put($conn, $dest.$name, $source, FTP_ASCII);
              if ($upload) {
                  success("File successfully uploaded");
              } else {
                  error("Something went wrong, contact the admin");
              }
          } else {
          error("Could not log in to server");
          }
      } else {
          error("Could not connect to file server");
      }
  
      ftp_close($conn);
  }
  </code></pre>