title: Warning: ftp_put(): Filename invalid, PHP FTP Upload Script
body: <p>I've got error when i tried to upload my files to ftp server. I'm able to connect to my FTP server, but the ftp_put(); keeps returning an error message</p>
  
  <p>This is my html form submission </p>
  
  <pre><code>&lt;form action="upload_file.php" enctype="multipart/form-data" method="post"&gt;
  &lt;input name="file" type="file" /&gt;
  &lt;input name="submit" type="submit" value="Upload File" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>And this is my upload_file.php script</p>
  
  <pre><code>&lt;?php
  $ftp_server = "xxx";
  $ftp_user_name = "xxx";
  $ftp_user_pass = "xxx";
  $destination_file = "/Iklan_Output/". $_FILES["file"]["name"]; // returns /Iklan_Output/file.test
  $source_file = $_FILES["file"]["tmp_name"]; //decoy
  $new_src_file = "E:\\ta\\temp\\" . $_FILES["file"]["name"]; // directory to the file
  
  // set up basic connection
  $conn_id = ftp_connect($ftp_server,20,900);
  
  
  // login with username and password
  $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 
  
  // check connection
  if ((!$conn_id) || (!$login_result)) { 
      echo "FTP connection has failed!";
      echo "Attempted to connect to $ftp_server for user $ftp_user_name"; 
      exit; 
  } else {
      echo "Connected to $ftp_server, for user $ftp_user_name";
  }
  
  ftp_pasv($conn_id, true);
  
  
  // moves file from temporary to specific folder, which is used for new source_file destination
  
  if ($_FILES["file"]["error"] &gt; 0)
      {
          echo "Error: " . $_FILES["file"]["error"] . "&lt;br&gt;";
      }
  else
      {
          echo "Upload: " . $_FILES["file"]["name"] . "&lt;br&gt;";
          echo "Type: " . $_FILES["file"]["type"] . "&lt;br&gt;";
          echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB&lt;br&gt;";
          echo "Stored in: " . $_FILES["file"]["tmp_name"]. "&lt;br&gt;";
  
      if (file_exists("E:\\ta\\temp\\" . $_FILES["file"]["name"]))
          {
              echo $_FILES["file"]["name"] . " already exists. ";
          }
  
      else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "E:\\ta\\temp\\" . $_FILES["file"]["name"]);
      echo "Temporarily Stored in: " . "E:\\ta\\temp\\" . $_FILES["file"]["name"]. "&lt;br&gt;";
      }
  
      }
  
  
  // upload the file
  
  $upload = ftp_put($conn_id, $destination_file, $new_src_file, FTP_BINARY); 
  
  
  // check upload status
  if (!$upload) { 
  echo "FTP upload has failed!";
  } else {
  echo "Uploaded $source_file to $ftp_server as $destination_file";
  }
  
  
  // close the FTP stream 
  ftp_close($conn_id);
  ?&gt;
  </code></pre>
  
  <p>I've tried, and always getting an Warning: ftp_put(): Filename invalid error,</p>
  
  <p>Thank you!</p>
  
  <p><strong>Update</strong> solved, the code is now working, thanks guys!</p>