Jump to content

Uploading files wit ftp_put but times out


gazfocus

Recommended Posts

I have created an upload form which uses ftp_put in order to upload files to my website as my hosts maximum php file upload size is 2MB and I do not have root access to the php.ini file.

 

This works great on small files but most of the files that will be uploaded will be around 15MB-30MB and because the form uses method="post" it times out after a couple of minutes.

 

Does anyone know if it's possible to change the timeout length?

Is there a function that can split up the file into 2MB chunks and reassemble it on the server (as with TCP packets)?

Also does anyone know how I can create a progress bar for the upload?

 

Thanks in advance

Link to comment
Share on other sites

set_time_limit might work for you.

I've just done a bit of research on set_time_limit but it looks like it doesn't override the HTTP timeout :(

 

The only way (which may not work I have mixed results) is set an increment timer in the code, and after x seconds echo a "." to the screen to keep the browser session alive...

 

Something like this:

<?php
$sizeTime = 1000; // set size time to 1,000 seconds for fun
while ($x) {
     echo ".";
     sleep(30); // sleep for 30 seconds.
     if (($i*30) == $sizeTime) {
        $x = false;
     }
}

echo "Finished";
?>

 

After the 1,000 seconds it should exit the loop and display "Finished"

 

Granted I have never used this with an upload script, only a large loop script. You may want to look into an AJAX/Flash uploader as I think you can keep those alive and upload about any size file you want...I have never used either but yea.

Link to comment
Share on other sites

premiso: can't do that dot thing because it nothing would be output until the script was done executing anyways.  He would indeed have to look into ajax/flash for that.  In fact, I think that might actually be the solution: an ajax/flash preloader % loaded type script might have the side-effect of keeping your http session alive.

Link to comment
Share on other sites

premiso: can't do that dot thing because it nothing would be output until the script was done executing anyways.  He would indeed have to look into ajax/flash for that.  In fact, I think that might actually be the solution: an ajax/flash preloader % loaded type script might have the side-effect of keeping your http session alive.

 

Yea, I did not think so. I know it worked for me with large queries I was trying to do via php, but that is not a file upload obviously =)

Link to comment
Share on other sites

umm...unless you have some php setup that somehow transcends what php normally does, I'm afraid you are mistaken.  The server sends nothing to the client until after the script is done executing.  If you had a really large query that returned obscene amounts of results, and echoed this obscene amount of results, it may look like it's sending it as it's coming, but that's because the browser is rendering it as it loads, not because the server is sending it 1 line at a time.

Link to comment
Share on other sites

umm...unless you have some php setup that somehow transcends what php normally does, I'm afraid you are mistaken.  The server sends nothing to the client until after the script is done executing.

 

I will have to look at the code I wrote. I know it worked at one time, but you are probably right. I will see if I cannot find it and figure out what I changed to make it work.

 

Actually I found it, I was using ob_flush and flush...

 

<?php
set_time_limit(505);
$sizeTime = 500; // set size time to 500 seconds for fun
$x=true;

$i=0;
while ($x) {
     echo ".";
 ob_flush();
 flush();
     
     sleep(30); // sleep for 30 seconds.
     if (($i*30) > $sizeTime) {
        $x = false;
     }
    $i++;
}

echo "<br />Finished";

?>

 

That seems to work for me....

 

EDIT: Forgot the i increment =)

EDIT:EDIT: also changed the == to > due to another possible infinite loop =)

EDIT:EDIT:EDIT:

 

umm...unless you have some php setup that somehow transcends what php normally does, I'm afraid you are mistaken.  The server sends nothing to the client until after the script is done executing.  If you had a really large query that returned obscene amounts of results, and echoed this obscene amount of results, it may look like it's sending it as it's coming, but that's because the browser is rendering it as it loads, not because the server is sending it 1 line at a time.

 

I would say it was more of me taking a CSV file with over 10,000 lines in it and converting it to MySQL to be entered into a new database. I wanted it done on the fly so I could just let the process run (I did not even think about using the CLI at this time) but yea that worked like a charm for me to run through that whole database and convert it from CSV to the new MySQL db version (columns different names etc).

Link to comment
Share on other sites

hmm...interesting...at face value, that does indeed seem to work.  I'll look into the manual entries for flush and ob_flush to see what limitations, trade-offs, etc... there are.  I mean, I recognize them and know what those things are in a general sense (due to people whining about header already sent errors all the time), but I've never really looked that deeply into them, as I've never really needed to use them. 

Link to comment
Share on other sites

Thanks for all your help guys. I have found a couple of free flash uploaders but they seem so confusing (unless I'm being thick).

 

The thing is, I want a form where the editor can fill in data such as 'Sermon Title', 'Speaker', 'Sermon Date', and then I need the uploader to update the MP3 file and a Notes file. Once uploaded, I then need the Sermon Title, Speaker, Sermon Date, MP3 Path, MP3 size, Notes Path and Notes file type to be stored in my MySQL database.

 

The Flash Uploaders that I've seen are great but I can't figure out how to build them into a form and then deal with all the data as well as the code is very complicated.

 

Can someone help?

Link to comment
Share on other sites

hmm...interesting...at face value, that does indeed seem to work.  I'll look into the manual entries for flush and ob_flush to see what limitations, trade-offs, etc... there are.  I mean, I recognize them and know what those things are in a general sense (due to people whining about header already sent errors all the time), but I've never really looked that deeply into them, as I've never really needed to use them. 

 

lol agreed. I actually found the example in the user comments to figure that out. I never understood what the ob_'s purpose was before until I saw that and was like AHHH! =)

Link to comment
Share on other sites

Thanks for all your help guys. I have found a couple of free flash uploaders but they seem so confusing (unless I'm being thick).

 

The thing is, I want a form where the editor can fill in data such as 'Sermon Title', 'Speaker', 'Sermon Date', and then I need the uploader to update the MP3 file and a Notes file. Once uploaded, I then need the Sermon Title, Speaker, Sermon Date, MP3 Path, MP3 size, Notes Path and Notes file type to be stored in my MySQL database.

 

The Flash Uploaders that I've seen are great but I can't figure out how to build them into a form and then deal with all the data as well as the code is very complicated.

 

Can someone help?

 

 

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.