Reputation: 38
How can I copy foo/test.php
in bar/
directory? copy()
function in php needs a filename like foo/test.php
-> bar/test.php
. Thank you!
Upvotes: 0
Views: 125
Reputation: 11
Well, in fact, you can use that to get the target file name from source path: https://www.php.net/manual/en/function.basename.php
Example #1 basename() example
<?php
echo "1) ".basename("/etc/sudoers.d", ".d").PHP_EOL;
echo "2) ".basename("/etc/sudoers.d").PHP_EOL;
echo "3) ".basename("/etc/passwd").PHP_EOL;
echo "4) ".basename("/etc/").PHP_EOL;
echo "5) ".basename(".").PHP_EOL;
echo "6) ".basename("/");
?>
The above example will output:
1) sudoers
2) sudoers.d
3) passwd
4) etc
5) .
6)
Upvotes: 1
Reputation: 38
Already figured it out. Use basename(file)
. This will give you the file name of the file then concat it to your destination like 'bar/' . basename(file)
Upvotes: 0