简体   繁体   中英

PHP copy files from one directory to another throws error

I have two directories I am using, where I want to make a copy of the file in a different directory.

$dest = "/home/********/public_html/$userUName/SharedFiles/";
            $source = "/home/********/public_html/$username/$value";
            if(file_exists($dest))
            {
                //echo $source;
                //echo $dest;
                copy($source, $dest);
            }

$source and $dest are definitely getting the right values required, but it's throwing an error

Warning: copy(/home/********/public_html/johnny/SharedFiles/) [function.copy]: failed to open stream: Is a directory in /home/********/public_html/MainHomescreen.php on line 380

which is the copy line.

Have been through many options to fix it by googling. Have checked file permissions, as far as I can see I've got everything in the right place, so have come to a dead end of where I've gone wrong!

PHP copy function is used to copy Files not Directories. Your destination is a Directory, because it ends with '/' .

To solve your problem, you must also add the file name to be created:

$dest = "/home/********/public_html/$userUName/SharedFiles/SomeNewFile.txt";

This is also true for the source.

Good luck,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM