简体   繁体   English

由于文件名中包含特殊字符,因此无法复制文件

[英]Can't copy file due to special characters in filename

I would like to copy a file in Symfony2, but I'm getting an error: 我想在Symfony2中复制文件,但出现错误:

Symfony\\Component\\Filesystem\\Exception\\FileNotFoundException: Failed to copy "../../../public_html/uploads/images/2011/03/MG_3839-ba o.jpg" because file does not exist

$fs = new Filesystem();
$fs->copy('../../../public_html/uploads/images/'.$image, '../../../public_html/uploads/tmp/'.$image, true);

var_dump($image) gives 2011/03/MG_3839-baño.jpg and mb_detect_encoding($image) gives ASCII . var_dump($image)提供2011/03/MG_3839-baño.jpgmb_detect_encoding($image)提供ASCII Why is Symfony looking for a filename containing the sign? 为什么Symfony寻找包含``符号的文件名? I can't figure out where that sign is coming from, since var_dump() gives the correct filename. 由于var_dump()提供了正确的文件名,因此我无法确定该符号来自何处。

Try this command : 试试这个命令:

$fs = new Filesystem();

$image = iconv("UTF-8", "ISO-8859-1//TRANSLIT", $image); $ image = iconv(“ UTF-8”,“ ISO-8859-1 // TRANSLIT”,$ image);

$fs->copy('../../../public_html/uploads/images/'.$image, '../../../public_html/uploads/tmp/'.$image, true);

$ file_name = strtr($ file_name,“áéíóúâêôààõçÁÉÍÓÚÂÊÔÀÃÕǺª”,“ aeiouaeoaaocAEIOUAEOAAOCoa”);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM