Home  >  Article  >  Backend Development  >  What to do if php copy fails

What to do if php copy fails

藏色散人
藏色散人Original
2020-08-06 10:29:143964browse

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.

What to do if php copy fails

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn