I want to do a simple copy using a ajax call. this is my code but it does not work . i kepp getting : a copy(../../images/merchant/particulars/208/) failed to open stream: Is a directory in some/filepath on scriptname.php line x , kind of error.
corrected code:
$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!";
}
Please read your error.
It says that your source file is not a file, but directory.
Simple debugging could always solve your problems:
It will show you, that
$copyvaluein you example is empty.If you wonder why this is returning
TRUE…..it’s because directory
../../images/merchant/particulars/208/does exists.As manual says:
You should change it to:
Another thing is destination shuld be file as well:
Manual: