I want to know three things about the following code
- is
getcwd()necessary - what is the job of
@in front ofmove_uploaded_file - what’s the function of
sleep(1)in this code
$destination_path = getcwd()."uploads".DIRECTORY_SEPARATOR;
$result = 0;
$target_path = $destination_path . basename($_FILES['myfile']['name']);
if(@move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path))
{
$result = 1;
}
sleep(1);
getcwd()returns the current directory (from which the running PHP script was invoked). This could very well be substituted with just"./"@()hides warnings in the default error handler from display. They can still be resurrected, might show up in logs, etc. Since you are probing the result anyway with theif()that’s entirely fine.The
sleep()is the only mysterious part about that code. Probably depends on how the upload interacts with some AJAX script, but otherwise this is very redundant.