Home >Backend Development >PHP Problem >What to do if php copy fails
Solution to php copy failure: First get the absolute path of the file to be copied; then copy the file to a path somewhere; then convert the character encoding through the iconv function; finally use copy to copy.
Recommended: "PHP Video Tutorial"
Solution to PHP copy Chinese name file failure
When copying a file, if the file path contains a Chinese name. Or if the copied file name has Chinese characters, an error will be reported
Solution
$source="./upload/测试.png";//要复制的文件的 绝对路径(服务器上的) $dest="./ipload/image/复制后.png";//将文件复制到某处的路径 $source = iconv('utf-8', 'gbk', $source);//使用后可以复制了 $dest = iconv('utf-8', 'gbk', $dest);//使用后可以复制了 if(copy($source,$dest)){ echo “成功”; }
The above is the detailed content of What to do if php copy fails. For more information, please follow other related articles on the PHP Chinese website!