Moving files is rename
, not copy
:
bool rename ( string $oldname , string $newname [, resource $context ] )
Note that in Windows, rename
only moves between different disks from version 5.3.1
As for "not wanting" the name in the destination, it seems to me an artificial requirement of your code, but if that's what you want, just create a function for it (if the code were mine, of the name in both places and resolved).
Solution
function moveSemPorONome( $origemComNome, $destinoSemNome ) {
$partes = pathinfo( $origemComNome);
$destinoComNome = $destinoSemNome . DIRECTORY_SEPARATOR . $partes['basename'];
return rename( $origemComNome, $destinoComNome );
}
Please note that I have not added protection to detect whether the destination path has the trailing slash or not. Provide the parameter without the slash (or adjust the function, probably using rtrim
to get the final slash).
If you really want to use copy
Just use exactly the same function, changing the line of the return to
return copy( $origemComNome, $destinoComNome ) && unlink( $origemComNome );
In this case, you need to adjust the function as you see fit to return and treat situations like the copy succeeded, but the deletion does not.