Move files is with rename
, and not with copy
:
bool rename ( string $oldname , string $newname [, resource $context ] )
Note that in Windows, the rename
only moves between different disks from version 5.3.1
As for "not wanting" to put the name on the target, 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 was mine, I would simply put the name variable in both places and solved).
Solution
function moveSemPorONome( $origemComNome, $destinoSemNome ) {
$partes = pathinfo( $origemComNome);
$destinoComNome = $destinoSemNome . DIRECTORY_SEPARATOR . $partes['basename'];
return rename( $origemComNome, $destinoComNome );
}
Note that I have not added protection to detect if the destination path is with the final bar or not. Provide the parameter without the slider (or add adjust the function, probably using rtrim
to remove the final bar).
If you really want to use the copy
Just use exactly the same function, changing the Return line to
return copy( $origemComNome, $destinoComNome ) && unlink( $origemComNome );
In this case, you need to adjust the function the way you think it is appropriate to return and treat situations like the copy being successful, but the deletion is not.
thanks for the tip
– gezer