Jump to content

[SOLVED] help with copy function


shiggydiggy

Recommended Posts

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

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">

 

 

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

@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 :)

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.