[英]php copy() does not work
I want to do a simple copy using a ajax call. 我想使用ajax调用进行简单复制。 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.
我无法获取:复制(../../images/merchant/particulars/208/)无法打开流:scriptname.php第x行上some / 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!";
}
Please read your error. 请阅读您的错误。
copy(../../images/merchant/particulars/208/) failed to open stream: Is a directory in some/filepath
It says that your source file is not a file, but directory. 它说您的源文件不是文件,而是目录。
Simple debugging could always solve your problems: 简单的调试总是可以解决您的问题:
$image_to_copy ='../../images/merchant/particulars/'.$copyfromthisstore.'/'.$copyvalue;
echo $image_to_copy; // yes, that could give you the answer
It will show you, that $copyvalue
in you example is empty. 它会告诉您, 示例中的
$copyvalue
为空。
If you wonder why this is returning TRUE
... 如果您想知道为什么这会返回
TRUE
...
if(file_exists($image_to_copy)){
..it's because directory ../../images/merchant/particulars/208/
does exists. ..这是因为目录
../../images/merchant/particulars/208/
确实存在。
As manual says: 如手册所述:
You should change it to: 您应该将其更改为:
if(is_file($image_to_copy)){
Another thing is destination shuld be file as well: 另一件事是目的地也应该是文件:
copy($image_to_copy, $dir.'file.jpg');
Manual: 手册:
I think you are confusing a simple thing. 我认为您在混淆一个简单的事情。 Here is a simple example on how to use
copy()
这是一个有关如何使用
copy()
的简单示例
$file = 'path/to/filename.ext'; // Example: http://adomain.com/content/image.jpg
$destination_folder = 'path/of/the/destination/folder';
//example: $_SERVER["DOCUMENT_ROOT"]."/content/files/"
// Execute the copy function
copy($file, $destination_folder.'/newFilaname.ext');
Use this function 使用这个功能
!move_uploaded_file($image_to_copy, $dir)
http://php.net/manual/en/function.move-uploaded-file.php http://php.net/manual/zh/function.move-uploaded-file.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.