Results 1 to 4 of 4

Thread: copy() function does not work

  1. #1
    Join Date
    May 2004
    Posts
    530
    Rep Power
    0

    Default copy() function does not work

    Hi you all. I have what seem to be a simple task but it does not work. I want to copy images dynamically . I keep getting this error:

    copy(../../images/merchant/particulars/208/) failed to open stream: Is a directory in some/filepath on scriptname.php line x.

    The path above is the destination folder which i know exists and the image i want to copy resides somewhere like this:

    ../../images/merchant/particulars/652/imagename.jpg.

    here an extract from my code:


    Code:
                           
    		$dir = '../../images/merchant/particulars/'.$copytothisstore.'/';
    		$image_to_copy = '../../images/merchant/particulars/'.$copyfromthisstore.'/'.$copyvalue;
    			
    
    	       
    		if(file_exists($image_to_copy)){
    			
    			//chk if there is a folder created for this store if not create it and copy
    			if(!file_exists($dir) || !is_dir($dir)){
                                       mkdir($dir, 0777);  
    				   chmod($dir, 0777);//force 777 rights
    				  
    				  //copy the image 
    				  if (!copy($image_to_copy, $dir)) {
                                             echo "failed to copy $image_to_copy\n";
                                       } else {
    					  echo"all is well!!";
    			           }
    				  
                           } else { //if the folder already exist just copy
    		   
                             chmod($dir, 0777); //force 777 rights
    		         if (!copy($image_to_copy, $dir)) {
                               echo "failed to copy $image_to_copy\n";
                            } else {
    		           echo"all is well!!";
    		        }
    				   
    		   }	   		   
    		
              }
    "...men are that they might have joy."
    Nephi

  2. #2
    Join Date
    May 2004
    Posts
    530
    Rep Power
    0

    Default

    Just had an epiphany. The answer is copy('images/249/images.jpg','images/230/image.jpg'); not copy('images/249/images.jpg','images/230/');
    "...men are that they might have joy."
    Nephi

  3. #3
    Join Date
    May 2004
    Posts
    530
    Rep Power
    0

    Default

    Full corrected code posted

    $dir_to_make = '../../images/merchant/particulars/'.$copytothisstore;
    $dir = '../../images/merchant/particulars/'.$copytothisstore.'/'.$copyvalue;
    $image_to_copy = '../../images/merchant/particulars/'.$copyfromthisstore.'/'.$copyvalue;






    if(is_file($image_to_copy)){

    //chk if there is a folder created for this store
    if(!is_dir($dir_to_make)){
    mkdir($dir_to_make, 0755);
    chmod($dir_to_make, 0755);

    //copy the image
    if (!copy($image_to_copy,$dir)) {
    echo "failed to copy $image_to_copy\n";
    } else {
    echo"all is well!!";
    }

    } else {
    chmod($dir_to_make, 0755);
    if (!copy($image_to_copy,$dir)) {
    echo "failed to copy $image_to_copy\n";
    } else {
    echo"all is well!!";
    }

    }


    echo"$image_to_copy does exist!";
    } else{
    echo"$image_to_copy does not exist!";
    }
    "...men are that they might have joy."
    Nephi

  4. #4
    Join Date
    Feb 2003
    Posts
    3,184
    Rep Power
    0

    Default

    hahah, I was wondering what was the problem. Also I think some shared host servers recommend 775 instead of 777.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •