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!!";
}
}
}