shiggydiggy Posted September 7, 2009 Share Posted September 7, 2009 I wrote this script to move hosts without downloading all my stuffs to my HDD again. Got one problem, PHP times out after 30 seconds, which is not enough for some files. Here's my code <html> <body> <form action="copy2.php" method="post" enctype="multipart/form-data"> <label for="file">File location:</label> <input type="text" name="filelocation" id="file" /> <label for="file">Destination file name:</label> <input type="text" name="filename" id="filename" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> </body> </html> <?php $file = $_POST['filelocation']; $newfile = $_POST['filename']; if (!copy($file, $newfile)) { echo "failed to copy $file...\n"; }else{ echo "successfully copied $file to (localdir)/$newfile...\n"; } ?> Link to comment https://forums.phpfreaks.com/topic/173399-solved-help-with-copy-function/ Share on other sites More sharing options...
bundyxc Posted September 7, 2009 Share Posted September 7, 2009 Hmm.. unless you can break it into seperate chunks, and move each individually, I don't know how you're going to go about doing this. Why are you using PHP to move files though? Wouldn't FTP be easier..? Link to comment https://forums.phpfreaks.com/topic/173399-solved-help-with-copy-function/#findComment-914068 Share on other sites More sharing options...
shiggydiggy Posted September 7, 2009 Author Share Posted September 7, 2009 I wouldn't know how to move it by FTP without downloading the file first. I don't want to download my files because i'm in the land down under on 6GB BW cellular internet - It's just not feasible. Link to comment https://forums.phpfreaks.com/topic/173399-solved-help-with-copy-function/#findComment-914072 Share on other sites More sharing options...
dave_sticky Posted September 7, 2009 Share Posted September 7, 2009 If you have access to the php.ini file on your server, you can change this timeout away from the default at the max_execution_time and max_input_time values. Alternately, (I've not tried this before) you can use set_time_limit(); at the top of your PHP file (before the headers are sent) to change the default. set_time_limit(0); // I think this removes the timeout altogether set_time_limit(300); // This would set it to 300 seconds (so 5 minutes) It may also be erroring because the files exceed the default maximum file size. The code below between your opening and closing tags should override what PHP considers the max file size to be (in this case, changing it to 5MB) <input name="MAX_FILE_SIZE" value="5242880" type="hidden"> Link to comment https://forums.phpfreaks.com/topic/173399-solved-help-with-copy-function/#findComment-914076 Share on other sites More sharing options...
bundyxc Posted September 7, 2009 Share Posted September 7, 2009 If you have access to the php.ini file on your server, you can change this timeout away from the default at the max_execution_time and max_input_time values. Alternately, (I've not tried this before) you can use set_time_limit(); at the top of your PHP file (before the headers are sent) to change the default. set_time_limit(0); // I think this removes the timeout altogether set_time_limit(300); // This would set it to 300 seconds (so 5 minutes) It may also be erroring because the files exceed the default maximum file size. The code below between your opening and closing tags should override what PHP considers the max file size to be (in this case, changing it to 5MB) <input name="MAX_FILE_SIZE" value="5242880" type="hidden"> Hmm.. that's tricky. So, I'm curious though... obviously if your form was passed through HTTP POST/GET, then the maximum file size would be easily editable by the end user, correct? By the way, found a site that might do the trick for you, if somehow dave_sticky's doesn't. http://directransfer.net Link to comment https://forums.phpfreaks.com/topic/173399-solved-help-with-copy-function/#findComment-914080 Share on other sites More sharing options...
Garethp Posted September 7, 2009 Share Posted September 7, 2009 Doesn't PHP have FTP resources, that let you make your server access another server through FTP and download it directly, through FTP? Link to comment https://forums.phpfreaks.com/topic/173399-solved-help-with-copy-function/#findComment-914081 Share on other sites More sharing options...
shiggydiggy Posted September 7, 2009 Author Share Posted September 7, 2009 dave_sticky, you are the man! set_time_limit(0); works perfect Link to comment https://forums.phpfreaks.com/topic/173399-solved-help-with-copy-function/#findComment-914083 Share on other sites More sharing options...
dave_sticky Posted September 7, 2009 Share Posted September 7, 2009 @shiggydiggy - no problem! I'll have to add that to my list of useful functions. FYI - don't use that regularly... If you accidentally stick a page into an infinite loop, when it has that code at the top, it really will be infinite! @bundyxc - Interesting... I'm not sure. I can see how it would be vulnerable to change if you used the GET method, but how could it be changed if the POST method was used? (in fact, never mind. That's a hacking / code exploitation question, so probably best not to answer it). Either way it's best to control that sort of thing through the php.ini file on the server and not via HTML for extra security Link to comment https://forums.phpfreaks.com/topic/173399-solved-help-with-copy-function/#findComment-914086 Share on other sites More sharing options...
shiggydiggy Posted September 7, 2009 Author Share Posted September 7, 2009 does that crash PHP on the server? Link to comment https://forums.phpfreaks.com/topic/173399-solved-help-with-copy-function/#findComment-914096 Share on other sites More sharing options...
dave_sticky Posted September 7, 2009 Share Posted September 7, 2009 Shouldn't do, but it could crash the server - depends on your error log settings. For my server that would fill my error log very quickly, causing the disk space available to drop rapidly, eventually resulting in 0% disk space available and a server that can't work. Link to comment https://forums.phpfreaks.com/topic/173399-solved-help-with-copy-function/#findComment-914102 Share on other sites More sharing options...
shiggydiggy Posted September 7, 2009 Author Share Posted September 7, 2009 it also depends on what sort of loop it gets into, i guess. not much possibility for that with such a short script, right? Link to comment https://forums.phpfreaks.com/topic/173399-solved-help-with-copy-function/#findComment-914103 Share on other sites More sharing options...
dave_sticky Posted September 7, 2009 Share Posted September 7, 2009 Well potentially even the smallest script could cause serious problems... This for example: $count = 1; while($count < 10) { echo "Count is less than 10"; echo $something; } $count is not incremented so the condition in the while loop will always be true. It will loop forever, crashing probably the user's computer and and also filling the error log with a warning that $something doesn't exist. Link to comment https://forums.phpfreaks.com/topic/173399-solved-help-with-copy-function/#findComment-914106 Share on other sites More sharing options...
bundyxc Posted September 7, 2009 Share Posted September 7, 2009 $i = 0; while (1) { //Or, you could just do it intentionally. $i++; } Link to comment https://forums.phpfreaks.com/topic/173399-solved-help-with-copy-function/#findComment-914112 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.