Jump to content

Really important. Can't upload large files


mendoz

Recommended Posts

Hey,

 

This little bastard time out when uploading large files, something larger than 5MB.

 

This ultra urgent,

 

If someone has a nice upload script let me know.

 

Thanks

 

<?php

// we connect to the database
require("../conn.php");
// we get the id
$id = $_GET['id'];


//uses $_FILES[] global array
//see manual for older PHP version info

//This function will be used to get the extension from the filename
function get_extension($file,$length=-1){
$p = strrpos($file,".");
$p++;
if($length!=-1){
  $ext = substr($file,$p,$length);
}
if($length==-1){
  $ext = substr($file,$p);
}
$ext = strtolower($ext);
return $ext;
}

//Not good practice, but here anyway
//change to suit your needs
//also some have to be set in the ini
//for this to correctly work

//2meg max
ini_set("upload_max_filesize","200M");

//turn on file uploads
ini_set("file_uploads","1");

//set your temp dir
ini_set("upload_tmp_dir","/tmp");

//set post size large enough to accomidate
//3 2meg files and some overhead
ini_set("post_max_size","200M");

?>
<html>
<head>
  <title>ftp connect and upload</title>
</head>
<body>
<?php
//check to see if we have submited yet
if($_POST["submit"]!="submit"){
//not yet so lets make the form
?>
<p>Upload Files to ftp site (200M MAX)</p>
<p>
<form name="fileup" method="post" enctype="multipart/form-data" action="<?php echo $PHP_SELF; ?>">
<input type="file" name="userfiles[]">
<br>
<!-- change below to your max -->
<input type="hidden" name="MAX_FILE_SIZE" value="200000000000">
<input type="submit" value="submit" name="submit">
</form>
</p>
<?php
}
//see if we have submited and that the files array has been set
if(($_POST["submit"]=="submit")&&(is_array($_FILES['userfiles']))){

ini_set('max_execution_time',12000);

$ftp_user_name="******"; //change to ftp username
$ftp_user_pass="********"; //change to ftp password
$ftp_server="********.web.aplus.net"; //change to ftp url
$ftp_dump_dir="/html/images/nannies/videos/"; //change to destination directory

//go through all the files
for($x=0;$x<count($_FILES['userfiles']['name']);$x++){

  //now we do some file checking

  //check to see if file is there
  if($_FILES['userfiles']['name'][$x]!="none"){
  //file has a name
  //check filesize
      if($_FILES['userfiles']['size'][$x]!=0){
        //file is larger than 0 bytes
          //Check to see if it is uploaded
          if(is_uploaded_file($_FILES['userfiles']['tmp_name'][$x])){
               //file has been uploaded!
             //let the user know their file has be uploaded
             echo "file ".$_FILES['userfiles']['name'][$x]." uploaded!<br>";
             //conect to ftp server
             $conn_id = ftp_connect($ftp_server);
            // 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!<br>";
              echo "Attempted to connect to $ftp_server for user $ftp_user_name";
              exit;
            } else {
                 echo "Connected to $ftp_server! <br>";
                 //set PASV mode
                 if(!ftp_pasv($conn_id,TRUE)){
                     echo "Could not enter PASV mode!";
                 }
                 //rename to file#_date.ext
                 $filename = "nanny".$id;
                 $filename.= ".".get_extension($_FILES['userfiles']['name'][$x],3);

                 //change directory
                 if (@ftp_chdir($conn_id, $ftp_dump_dir)) {
                     //maybe you want to make sure we are in the correct directory
                    echo "Current directory is now : ", ftp_pwd($conn_id), "\n";
                } else {
                  //you want to know if it didn't work
                  echo "Couldn't change directory\n";
                }

                  //upload the file and let the user know what happened
                if(ftp_put($conn_id,$filename,$_FILES['userfiles']['tmp_name'][$x],FTP_BINARY)){
                       echo "File ".$_FILES['userfiles']['name'][$x]." was sent successfully<br>";
                    echo "File was named ".$filename."<br>";
                    $uploadsql = "UPDATE `nannies` SET `vid`='".$filename."' WHERE `id`=$id";
				mysql_query($uploadsql,$connection);
                }else{
                       echo "There was a problem sending file ".$_FILES['userfiles']['name'][$x]."<br>";;
                         }
                }
                // close the FTP stream
                ftp_close($conn_id);
            }
            else echo"File was not uploaded!<br>";
        }
    }
    echo "<br>";

}//end for loop

}
//That's all folks!
ini_set('max_execution_time',30);
?>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.