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

 

 

Link to comment
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">

 

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
Share on other sites

@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
Share on other sites

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