467,146 Members | 1,313 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,146 developers. It's quick & easy.

is there a possibility of getting rid of this error message?

anfetienne
256MB
Hi all,

this is real simple, I've written this code so I can duplicate images/files after uploading it with jumploader (this doesn't allow for duplicates during the upload process like standard upload handlers... sucks).

It does what it should do which is copy files from one directory to another but I get a error message "Warning: copy() [function.copy]: The first argument to copy() function cannot be a directory in /home/veresour/public_html/streammii.com/q/forTest.php on line 34"... is there a way to avoid this or atleast not display it?

Expand|Select|Wrap|Line Numbers
  1. $pathA = "user/aetienne/photos/aetienne853139394/tmp/l/";
  2. $pathB = "user/aetienne/photos/aetienne853139394/tmp/t/";
  3.  // path to the directory to read ( ./ reads the dir this file is in)
  4.     if ($handle = opendir($pathA)) {
  5.            while (false !== ($file = readdir($handle))) {
  6.         if ($file != "." && $file != "..") {
  7.             if(!is_dir($file)){
  8.                 $item[] = $file;
  9.                 sort($item,SORT_REGULAR);
  10.                 }
  11.                }
  12.            }
  13.            closedir($handle);
  14.     }
  15.         $total_items = count($item);
  16.  
  17.         print_r($item);
  18.  
  19.         echo '<br/>';
  20.  
  21.         $total_items = count($item);
  22.         echo $total_items;
  23.  
  24.         for($n=0; $n<=$total_items; $n++) {
  25.             $source = $pathA . $item[$n];
  26.             $destination = $pathB . $item[$n];
  27.             $thumbnailCopy = copy($source, $destination);
  28.         }
  29.  
Jul 9 '10 #1

✓ answered by zorgi

OK

Your problem is in line 24 "for loop" should look like this:

for($n=0; $n<=$total_items - 1; $n++) {

}

But it can be done without it:
Expand|Select|Wrap|Line Numbers
  1. $pathA = "user/aetienne/photos/aetienne853139394/tmp/l/";
  2. $pathB = "user/aetienne/photos/aetienne853139394/tmp/t/";
  3.  
  4. if($handle = opendir($pathA)) {
  5.     while (false !== ($file = readdir($handle))) {
  6.         if ($file != "." && $file != "..") {
  7.             if(!is_dir($file)){
  8.                 $destination = $pathB . $file;
  9.                 copy($file, $destination);
  10.             }
  11.         }
  12.     }
  13.     closedir($handle);
  14. }
  15.  

  • viewed: 1186
Share:
3 Replies
zorgi
Expert 256MB
OK

Your problem is in line 24 "for loop" should look like this:

for($n=0; $n<=$total_items - 1; $n++) {

}

But it can be done without it:
Expand|Select|Wrap|Line Numbers
  1. $pathA = "user/aetienne/photos/aetienne853139394/tmp/l/";
  2. $pathB = "user/aetienne/photos/aetienne853139394/tmp/t/";
  3.  
  4. if($handle = opendir($pathA)) {
  5.     while (false !== ($file = readdir($handle))) {
  6.         if ($file != "." && $file != "..") {
  7.             if(!is_dir($file)){
  8.                 $destination = $pathB . $file;
  9.                 copy($file, $destination);
  10.             }
  11.         }
  12.     }
  13.     closedir($handle);
  14. }
  15.  
Jul 9 '10 #2
anfetienne
256MB
I never thought of it that way... thanks for the heads up zorgi it's much appreciated
Jul 10 '10 #3
anfetienne
256MB
ok thanks again zorgi for the idea here is my final code that I tested and it works perfectly... it duplicates the images then resizes them according to width and height

Expand|Select|Wrap|Line Numbers
  1. include('SimpleImage.php');
  2. $pathA = "user/aetienne/photos/aetienne919500405/tmp/l/";
  3. $pathB = "user/aetienne/photos/aetienne919500405/tmp/t/";
  4.  
  5.     if ($handle = opendir($pathA)) {
  6.            while (false !== ($file = readdir($handle))) {
  7.         if ($file != "." && $file != "..") {
  8.             if(!is_dir($file)){
  9.                 $source = $pathA . $file;
  10.                 $destination = $pathB . $file;
  11.                 copy($source, $destination);
  12.  
  13.  
  14.  $details = array();
  15.  $details = getimagesize($source);
  16.  $detailsWidth = $details[0];
  17.  $detailsHeight = $details[1];
  18.  
  19.              if ($detailsWidth > $detailsHeight){
  20.              $image = new SimpleImage();
  21.              $image->load("$source");
  22.              $image->resize(450,350);
  23.              $image->save("$source");
  24.  
  25.              $image = new SimpleImage();
  26.              $image->load("$destination");
  27.              $image->resize(100,70);
  28.              $image->save("$destination"); 
  29.              } 
  30.              elseif ($detailsHeight > $detailsWidth) {
  31.              $image = new SimpleImage();
  32.              $image->load("$source");
  33.              $image->resize(240,350);
  34.              $image->save("$source"); 
  35.  
  36.              $image = new SimpleImage();
  37.              $image->load("$destination");
  38.              $image->resize(70,100);
  39.              $image->save("$destination"); 
  40.              }
  41.                 }
  42.                }
  43.            }
  44.            closedir($handle);
  45.     }
  46.  
Jul 10 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Bill English | last post: by
1 post views Thread by riyaz | last post: by
2 posts views Thread by amita | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.