Copy a file, renaming it if the destination already exists.
Original Answer:

I'd put in some extra brackets in your while-loop for radability:

while ( file_exists($new_name) 
        &amp;&amp; (sha1_file($src) != sha1_file($new_name))
      );


And you shouldn't set file-permissions to 777 by default (660 or even less). Everything else looks quite ok in my eyes (although I don't like the do/while construct, but I guess that's more a personal thing)

Update for comment:

$srcSH1 = sha1_file($sec);
do
{
    // ...
}
while ( file_exists($new_name) 
        &amp;&amp; (sha1_file($new_name) != $srcSH1)
      );


You should move out the sha_file($src) as this doesn't change but is recalculated each iteration. And that's the case why I don't like do/while. Splits the $srcSH1 and the while-condition where it is used.