php - copy,rename和move_uploaded_file之间的差异

时间:2020-12-15 16:03:43

Are there differences when I use that functions? Why should I use one instead of the other one...

使用这些功能时是否存在差异?我为什么要用一个而不是另一个......

2 个解决方案

#1


41  

  • copy() copies the file - you now have 2 files, and for large files, this can take very long
  • copy()复制文件 - 您现在有2个文件,对于大文件,这可能需要很长时间

  • rename() changes the file's name, which can mean moving it between directories.
  • rename()更改文件的名称,这可能意味着在目录之间移动它。

  • move_uploaded_file() is basically the same as rename(), but it will only work on files that have been uploaded via PHP's upload mechanism. This is a security feature that prevents users from tricking your script into showing them security-relevant data.
  • move_uploaded_file()与rename()基本相同,但它只适用于通过PHP上传机制上传的文件。这是一项安全功能,可防止用户欺骗您的脚本向其显示与安全相关的数据。

In the future, I suggest looking up such information in the PHP Manual yourself.

将来,我建议您自己在PHP手册中查找此类信息。

#2


8  

I found this in the manual of move_uploaded_file():

我在move_uploaded_file()的手册中找到了这个:

Florian S. in H. an der E. [.de] at 17-Aug-2008 09:02

弗洛里安S.在H. an der E. [.de]于2008年8月17日09:02

move_uploaded_file (on my setup) always makes files 0600 (rw- --- ---) and owned by the user running the webserver (owner AND group). Even though the directory has a sticky bit set to the group permissions! I couldn't find any settings to change this via php.ini or even using umask().

move_uploaded_file(在我的设置上)总是生成文件0600(rw- --- ---)并由运行webserver(所有者AND组)的用户拥有。即使目录的粘性位设置为组权限!我找不到任何设置来改变这个通过php.ini甚至使用umask()。

I want my regular user on the server to be able to tar cjf the directory .. which would fail on files totally owned by the webserver-process-user; the copy(from, to) function obeys the sticky-bit though!

我希望服务器上的常规用户能够tar目录cjf目录..这对于webserver-process-user完全拥有的文件会失败;复制(从,到)功能虽然服从粘性位!

so it seems like copy and rename do a slightly different work.

所以复制和重命名似乎做了一个稍微不同的工作。

#1


41  

  • copy() copies the file - you now have 2 files, and for large files, this can take very long
  • copy()复制文件 - 您现在有2个文件,对于大文件,这可能需要很长时间

  • rename() changes the file's name, which can mean moving it between directories.
  • rename()更改文件的名称,这可能意味着在目录之间移动它。

  • move_uploaded_file() is basically the same as rename(), but it will only work on files that have been uploaded via PHP's upload mechanism. This is a security feature that prevents users from tricking your script into showing them security-relevant data.
  • move_uploaded_file()与rename()基本相同,但它只适用于通过PHP上传机制上传的文件。这是一项安全功能,可防止用户欺骗您的脚本向其显示与安全相关的数据。

In the future, I suggest looking up such information in the PHP Manual yourself.

将来,我建议您自己在PHP手册中查找此类信息。

#2


8  

I found this in the manual of move_uploaded_file():

我在move_uploaded_file()的手册中找到了这个:

Florian S. in H. an der E. [.de] at 17-Aug-2008 09:02

弗洛里安S.在H. an der E. [.de]于2008年8月17日09:02

move_uploaded_file (on my setup) always makes files 0600 (rw- --- ---) and owned by the user running the webserver (owner AND group). Even though the directory has a sticky bit set to the group permissions! I couldn't find any settings to change this via php.ini or even using umask().

move_uploaded_file(在我的设置上)总是生成文件0600(rw- --- ---)并由运行webserver(所有者AND组)的用户拥有。即使目录的粘性位设置为组权限!我找不到任何设置来改变这个通过php.ini甚至使用umask()。

I want my regular user on the server to be able to tar cjf the directory .. which would fail on files totally owned by the webserver-process-user; the copy(from, to) function obeys the sticky-bit though!

我希望服务器上的常规用户能够tar目录cjf目录..这对于webserver-process-user完全拥有的文件会失败;复制(从,到)功能虽然服从粘性位!

so it seems like copy and rename do a slightly different work.

所以复制和重命名似乎做了一个稍微不同的工作。