简体   繁体   English

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

[英]php - Differences between copy, rename and move_uploaded_file

Are there differences when I use that functions? 使用这些功能时是否存在差异? Why should I use one instead of the other one... 我为什么要用一个而不是另一个......

  • 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. move_uploaded_file()rename()基本相同,但它只适用于通过PHP上传机制上传的文件。 This is a security feature that prevents users from tricking your script into showing them security-relevant data. 这是一项安全功能,可防止用户欺骗您的脚本向其显示与安全相关的数据。

In the future, I suggest looking up such information in the PHP Manual yourself. 将来,我建议您自己在PHP手册中查找这些信息。

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). move_uploaded_file(在我的设置上)总是生成文件0600rw- --- --- )并由运行webserver(所有者AND组)的用户拥有。 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() . 我找不到任何设置来改变这个通过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; 我希望服务器上的常规用户能够tar cjf目录tar cjf目录..这对于webserver-process-user完全拥有的文件会失败; the copy(from, to) function obeys the sticky-bit though! copy(from, to)函数服从粘性位虽然!

so it seems like copy and rename do a slightly different work. 所以copyrename似乎做了一个稍微不同的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM