mikebrady81 Posted March 12, 2010 Share Posted March 12, 2010 Hey! I keep getting this message: Warning: copy() [function.copy]: The first argument to copy() function cannot be a directory in /Library/WebServer/Documents/RandysWebsite/newgallery.php on line 80 Here's the code: foreach($filenames as $value){ copy('/Library/WebServer/Documents/RandysWebsite/gallery/' . $foldername . '/' . $value . '', '/Library/WebServer/Documents/RandysWebsite/' . $foldername . '/images/' . $value . ''); } The line that starts with "copy" is line 80. What i'm trying to do: I have a folder "gallery" with random images that I won't always know the names of prior. I'm trying to move all of the images from gallery to "variable folder name/images/ Make sense? Thanks! Link to comment https://forums.phpfreaks.com/topic/195013-moving-multiple-files/ Share on other sites More sharing options...
severndigital Posted March 12, 2010 Share Posted March 12, 2010 are you sure all the contents are files? you may need to put something like foreach($filenames as $value){ if(!is_dir('/Library/WebServer/Documents/RandysWebsite/gallery/' . $foldername . '/' . $value)) { copy('/Library/WebServer/Documents/RandysWebsite/gallery/' . $foldername . '/' . $value, '/Library/WebServer/Documents/RandysWebsite/' . $foldername . '/images/' . $value); } } also I cleaned up the code a bit, you had some quotes in there you didn't really need. http://us.php.net/manual/en/function.is-dir.php Link to comment https://forums.phpfreaks.com/topic/195013-moving-multiple-files/#findComment-1025199 Share on other sites More sharing options...
MadTechie Posted March 12, 2010 Share Posted March 12, 2010 as the error says you can't copy a directory.. so you need to copy the files inside try something like this $dir = "/from/folder/"; $dirto = "/to/folder/"; if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if($file == "."||$file == "..") continue; copy($dir.$file, $dirto.$file); } closedir($dh); } } Link to comment https://forums.phpfreaks.com/topic/195013-moving-multiple-files/#findComment-1025201 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.