简体   繁体   English

PHP将临时文件移动/复制到新目录并重命名(性能)

[英]PHP move/copy temp file into a new directory and rename it ( performance )

i simply upload file from a html form. 我只是从html表单上传文件。

Now , once the file is uploaded php creates a temp file somewhere. 现在,一旦文件上传,php就会在某处创建一个临时文件。

I was wondering, is it faster to copy or move the file into a new directory? 我想知道,将文件复制或移动到新目录是否更快?

I saw these three methods available ssh2_scp_send() copy() move_uploaded_file(); 我看到这三个方法可用ssh2_scp_send() copy() move_uploaded_file(); , can someone explain differences between these methods and which is faster at the end? ,有人可以解释这些方法之间的差异,并在最后更快?

For each method i will go for using, i will need to rename the file anyway so the combination is copy or move + rename file. 对于我将使用的每个方法,我将需要重命名文件,因此组合是复制或移动+重命名文件。

At the end, is here a really faster solution, to move or copy file from a dir to another and rename it? 最后,这是一个非常快的解决方案,将文件从目录移动或复制到另一个并重命名它?

thank you 谢谢

Use move_uploaded_file() its the most simple method to move an uploaded file to its proper destination. 使用move_uploaded_file()是将上传文件移动到正确目的地的最简单方法。

In general a file move is much faster than file copy (in the same partition) because with move there is no actual file data being moved, only the fat is updated. 通常,文件移动比文件复制(在同一分区中)快得多,因为移动时没有移动实际文件数据,只更新fat

Move would be as faster than copy... 移动会比复制更快......

To move a file use the rename function. 要移动文件,请使用重命名功能。

To move an uploaded file move_uploaded_file is the way to go. 要移动上传的文件,move_uploaded_file是可行的方法。 It has a little overhead in that it check and ensures that the file was in fact the result of an upload. 它有一点开销,它检查并确保文件实际上是上传的结果。

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

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