I have a small problem. a friend needs a way to upload large files (ie. bigger then 40mbs) to his web server. He aparently had a php script that did this, however he recently moved over to 1and1 hosting and the script no longer works. So he asked me to come up with a method to upload large files. I tried several methods but none seemed to work. I've never really delt with uploading files bigger then 4mbs. So I went to php.net and found this upload snippet that uploads files using ftp. I tried it out and it seemed to work with files 4mbs or smaller. However when I try larger files it seems like its uploading but after 20 seconds it just refreshes the form as if nothing happen. I tried searching in the php.ini for any settings pertaining to php's ftp functions but could not find any. Does anyone know how I can make this work with larger files? Is there something I'm missing?

<?php
set_time_limit(0);
/*Fill in the Forms:
1) Server Path or IP like abc.com/1.2.3.4 only.
2) FTP Username
3) FTP Password
4) FTP Path, where you want to put the file, check the Folder permission first.
*/


  //-- SMTP Mail Function  By Aditya Bhatt
  if(isset($_POST['SubmitFile'])){
      $myFile = $_FILES['txt_file']; // This will make an array out of the file information that was stored.
      $file = $myFile['tmp_name'];  //Converts the array into a new string containing the path name on the server where your file is.

  $myFileName = basename($_FILES['txt_file']['name']); //Retrieve filename out of file path

  $destination_file = $_REQUEST['filepath'].$myFileName;
  #"/developers/uploadftp/aditya/".$myFileName;  //where you want to throw the file on the webserver (relative to your login dir)

  // connection settings
  $ftp_server = trim($_REQUEST['serverip']);  //address of ftp server.
  $ftp_user_name = trim($_REQUEST['username']); // Username
  $ftp_user_pass = trim($_REQUEST['password']);   // Password

  $conn_id = ftp_connect($ftp_server) or die("<span style='color:#FF0000'><h2>Couldn't connect to $ftp_server</h2></span>");        // set up basic connection
  #print_r($conn_id);
  //ftp_pasv($conn_id, true);
  //ftp_set_option($conn_id, FTP_TIMEOUT_SEC, 990);
  $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass) or die("<span style='color:#FF0000'><h2>You do not have access to this ftp server!</h2></span>");   // login with username and password, or give invalid user message
  if ((!$conn_id) || (!$login_result)) {  // check connection
         // wont ever hit this, b/c of the die call on ftp_login
         echo "<span style='color:#FF0000'><h2>FTP connection has failed! <br />";
         echo "Attempted to connect to $ftp_server for user $ftp_user_name</h2></span>";
         exit;
     } else {
     //    echo "Connected to $ftp_server, for user $ftp_user_name <br />";
  }

  $upload = ftp_put($conn_id, $destination_file, $file, FTP_BINARY);  // upload the file
  if (!$upload) {  // check upload status
     echo "<span style='color:#FF0000'><h2>FTP upload of $myFileName has failed!</h2></span> <br />";
  } else {
     echo "<span style='color:#339900'><h2>Uploading $myFileName Completed Successfully!</h2></span><br /><br />";
  }

  ftp_close($conn_id); // close the FTP stream
  }

  /* To allow people to choose which folder to move files in you can uncomment the server file path input box
	and edit the name and id to filepath*/

?>

<html>
  <head></head>
  <body>
        <form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
            Server IP Address: <input name="serverip" type="text" id="serverip" size="25" value=""/><br>
            Server Username: <input name="username" type="text" id="username" size="25" value=""/><br>
            Server Password: <input name="password" type="text" id="password" size="25" value=""/><br>
            Server File Path: <input name="filepath" type="text" id="filepath" size="35" value=""/><br>
            Please choose a file: <input name="txt_file" type="file" id="txt_file" tabindex="1" size="35" onChange="txt_fileName.value=txt_file.value" /><br><br>
            <input name="txt_fileName" type="hidden" id="txt_fileName" tabindex="99" size="1" />

        <input type="submit" name="SubmitFile" value="Upload File" accesskey="ENTER" tabindex="2" />
  </form>
  </body>
</html>

    This script still needs to upload file via http to the web server. Then it copies it to the ftp server.
    There is no way (that I know) to utilize ftp for uploading files from forms. There is no way to easily upload 40MB files. You can produce some system of uploading it with ordinary ftp client and then letting your page know.
    The reason, why it could work elsewhere, is php upload limit, which is by default 8MB. It could have been changed in php.ini on the other system, to something bigger.

      wilku wrote:

      This script still needs to upload file via http to the web server. Then it copies it to the ftp server.
      There is no way (that I know) to utilize ftp for uploading files from forms. There is no way to easily upload 40MB files. You can produce some system of uploading it with ordinary ftp client and then letting your page know.
      The reason, why it could work elsewhere, is php upload limit, which is by default 8MB. It could have been changed in php.ini on the other system, to something bigger.

      so it still uploads to a temp folder on the web server and then moves it over to using the ftp server? Thats kind of a useless function then..For some reason it works way waste then normal php uploading scripts though.

      Also I've tried changing all the php.ini parts to 80mbs. I've also changed time out times to 1 hour. I still cant manage to upload files larger then 5 or 6mbs. I'm guessing the only thing left is to just force people to use an ftp client to upload 😛.

        Write a Reply...