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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anfetienne
    Contributor
    • Feb 2009
    • 424

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

    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?

    Code:
    $pathA = "user/aetienne/photos/aetienne853139394/tmp/l/";
    $pathB = "user/aetienne/photos/aetienne853139394/tmp/t/";
     // path to the directory to read ( ./ reads the dir this file is in)
    	if ($handle = opendir($pathA)) {
       		while (false !== ($file = readdir($handle))) {
        	if ($file != "." && $file != "..") {
            	if(!is_dir($file)){
                	$item[] = $file;
    				sort($item,SORT_REGULAR);
                	}
           		}
       		}
       		closedir($handle);
    	}
    		$total_items = count($item);
    		
    		print_r($item);
    		
    		echo '<br/>';
    		
    		$total_items = count($item);
    		echo $total_items;
    		
    		for($n=0; $n<=$total_items; $n++) {
    			$source = $pathA . $item[$n];
    			$destination = $pathB . $item[$n];
    			$thumbnailCopy = copy($source, $destination);
    		}
  • zorgi
    Recognized Expert Contributor
    • Mar 2008
    • 431

    #2
    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:
    Code:
    $pathA = "user/aetienne/photos/aetienne853139394/tmp/l/";
    $pathB = "user/aetienne/photos/aetienne853139394/tmp/t/";
    
    if($handle = opendir($pathA)) {
    	while (false !== ($file = readdir($handle))) {
    		if ($file != "." && $file != "..") {
    			if(!is_dir($file)){
    				$destination = $pathB . $file;
    				copy($file, $destination);
    			}
    		}
    	}
    	closedir($handle);
    }

    Comment

    • anfetienne
      Contributor
      • Feb 2009
      • 424

      #3
      I never thought of it that way... thanks for the heads up zorgi it's much appreciated

      Comment

      • anfetienne
        Contributor
        • Feb 2009
        • 424

        #4
        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

        Code:
        include('SimpleImage.php');
        $pathA = "user/aetienne/photos/aetienne919500405/tmp/l/";
        $pathB = "user/aetienne/photos/aetienne919500405/tmp/t/";
        
        	if ($handle = opendir($pathA)) {
           		while (false !== ($file = readdir($handle))) {
            	if ($file != "." && $file != "..") {
                	if(!is_dir($file)){
        				$source = $pathA . $file;
        				$destination = $pathB . $file;
                        copy($source, $destination);
        				
        				
         $details = array();
         $details = getimagesize($source);
         $detailsWidth = $details[0];
         $detailsHeight = $details[1];
          
                     if ($detailsWidth > $detailsHeight){
                     $image = new SimpleImage();
                     $image->load("$source");
                     $image->resize(450,350);
                     $image->save("$source");
          
                     $image = new SimpleImage();
                     $image->load("$destination");
                     $image->resize(100,70);
                     $image->save("$destination"); 
                     } 
                     elseif ($detailsHeight > $detailsWidth) {
                     $image = new SimpleImage();
                     $image->load("$source");
                     $image->resize(240,350);
                     $image->save("$source"); 
        
                     $image = new SimpleImage();
                     $image->load("$destination");
                     $image->resize(70,100);
                     $image->save("$destination"); 
                     }
                    	}
               		}
           		}
           		closedir($handle);
        	}

        Comment

        Working...