我想使用ajax调用做一个简单的复制.这是我的代码,但它不起作用.我得到:副本(../../ images/merchant/particulars/208 /)无法打开流:在scriptname.php第x行的某个/ filepath中有一个目录,有点错误.
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!";
}
Run Code Online (Sandbox Code Playgroud)
请阅读你的错误.
copy(../../images/merchant/particulars/208/) failed to open stream: Is a directory in some/filepath
Run Code Online (Sandbox Code Playgroud)
它说你的源文件不是文件,而是目录.
简单的调试总能解决您的问题:
$image_to_copy ='../../images/merchant/particulars/'.$copyfromthisstore.'/'.$copyvalue;
echo $image_to_copy; // yes, that could give you the answer
Run Code Online (Sandbox Code Playgroud)
它会告诉你,那$copyvalue你的例子是空的.
如果你想知道为什么会这样TRUE......
if(file_exists($image_to_copy)){
Run Code Online (Sandbox Code Playgroud)
..是因为目录../../images/merchant/particulars/208/确实存在.
正如手册所说:
您应该将其更改为:
if(is_file($image_to_copy)){
Run Code Online (Sandbox Code Playgroud)
另一件事是目的地shuld也是文件:
copy($image_to_copy, $dir.'file.jpg');
Run Code Online (Sandbox Code Playgroud)
手册: