Does move_uploaded_file() automatically deletes the temporary uploaded file after SUCCESSful Move?

不想你离开。 提交于 2019-12-22 10:34:12

问题


My Question is: "Does move_uploaded_file() automatically deletes the temporary uploaded file after successful move ?"

Just to get out of the confusion that do i need to do this:

// Successful upload
if ( move_uploaded_file($file['tmp_name'], $destination) ) {
  unlink($file['tmp_name']);
  return TRUE;
} else {
  // Upload Failed
  unlink($file['tmp_name']);
  return FALSE;
}

Or is it not needed at all?


回答1:


You do not need to manually unlink() the temporary file; PHP cleans up after itself after a successful upload. The function is called move_uploaded_file, not copy_uploaded_file.




回答2:


Yes, it does.
http://php.net/manual/en/function.move-uploaded-file.php

Function description: This function checks to ensure that the file designated by filename is a valid upload file (meaning that it was uploaded via PHP's HTTP POST upload mechanism). If the file is valid, it will be moved to the filename given by destination.

This sort of check is especially important if there is any chance that anything done with uploaded files could reveal their contents to the user, or even to other users on the same system.

So we see here:

If the file is valid, it will be moved to the filename given by destination.




回答3:


Temporary File is Deleted Automatically. You dont have to delete it manually. move_uploaded_file function also not delete this temporary file.



来源:https://stackoverflow.com/questions/13840951/does-move-uploaded-file-automatically-deletes-the-temporary-uploaded-file-afte

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!