Jump to content

Recommended Posts

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

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

 

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);
    }
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.