Take the 2-minute tour ×

i simply upload file from a html form.

Now , once the file is uploaded php creates a temp file somewhere.

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(); , 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

share|improve this question
Move would be logical, you don't usually want to keep 2 copies of the same file unnecessarily on the server But you really have to benchmark it in order to find out which is faster –  Hanky 웃 Panky Jul 19 '13 at 6:23
@ØHankyPankyØ thank you but i need the faster one, logic for now doesn't matter since then i delete both files... –  bombastic Jul 19 '13 at 6:24
Move is faster than copy, because for move all you need is an update partition table no need to copy data –  DevZer0 Jul 19 '13 at 6:26
@DevZer0 do you mean scp or move_uploaded_file()? :) –  bombastic Jul 19 '13 at 6:27
why do you need scp unless your copying across network. i am talking in file system wise move is faster than a copy as long as its done to the same partition –  DevZer0 Jul 19 '13 at 6:29

2 Answers 2

Use move_uploaded_file() its the most simple method to move an uploaded file to its proper destination.

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.

share|improve this answer
ok, but what about ssh moving ? (obviously the connection will be pre-established) ... –  bombastic Jul 19 '13 at 6:45
ssh moving to the localhost? –  DevZer0 Jul 19 '13 at 6:46
yeah ssh from same server :D , crazy? :D –  bombastic Jul 19 '13 at 6:58

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. It has a little overhead in that it check and ensures that the file was in fact the result of an upload.

share|improve this answer
so rename will move a temp file to a new directory with new name? :O –  bombastic Jul 19 '13 at 6:45
Yes you supply it with the tmp file and the new file. for your case move_uploaded_file is probably the route to go. –  Orangepill Jul 19 '13 at 6:48
so can't i use rename to copy and rename file from tmp to new directory? or you suggest move_uploaded_file() cause it's faster? sorry i didn't catched you –  bombastic Jul 19 '13 at 6:58
you can use either... but since you are moving a file that was uploaded then move_uploaded_file is probably a better solution. –  Orangepill Jul 19 '13 at 6:59
but i would like to understand why buddy :D ... –  bombastic Jul 19 '13 at 7:01

Your Answer


