关于getcwd(),sleep()和@move_uploaded_file的一些问题。 提供工作代码

I want to know three things about the following code

  1. is getcwd() necessary
  2. what is the job of @ in front of move_uploaded_file
  3. 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 the if() 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.

I am familiar with this code. The authors stated intention for the sleep command was to insure that the upload bar always displays long enough for the user to see it.

http://www.ajaxf1.com/tutorial/ajax-file-upload-tutorial.html