php move_uploaded_file不起作用

I know this is an old question and I have found lots of tutorial on SO however, they cannot solve my problem.

I use my mac to set up a localhost for web programming and I try to upload a jpg file to my localhost directory "/Library/WebServer/Documents". But it gives hint unable to move.

my front end code is:

<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>

The php(upload_file.php) code is(there is some other checking codes for php file, copied from w3school):

move_uploaded_file($_FILES["file"]["tmp_name"] , "/Library/WebServer/Documents" . $_FILES["file"]["name"]);

And after I click the submit button, there is sth wrong printed on the screen.

Moreover, I did not find any tmp file in the file "/private/var/tmp", in which should be a tmp file...

  1. make sure your php file has enough rights to write into the directory.
  2. check if print_r($_FILES); lists anything, especially the size is important.