Imagick 无法载入中文文件名
Imagick 无法载入中文文件名
<?php<br><br><br>$filepath = 'F:\';<br>$filename="哈.tif";<br><br>$encoded_filename = urlencode($filename);<br>$encoded_filename = str_replace("+", "%20", $encoded_filename);<br><br>//$filename = iconv('utf-8', 'gb2312', $filename);<br>$jpgfilename = substr($filename,0,strrpos($filename,'.')).'.jpg';<br>$im = new Imagick($filepath.$filename);<br>$im->thumbnailImage(1200, 0);<br><br>$width = $im->getImageWidth() ;<br>$height = $im->getImageHeight();<br>$width800 = 1200;<br>$height800 = 1200*$height/$width;<br>$canvas = new Imagick();<br>$canvas->newImage($width, $height, '');<br>$canvas->setImageFormat("jpeg");<br>$canvas->compositeImage($im, imagick::COMPOSITE_OVER, 20, 10);<br>$canvas->writeImage($filepath.$jpgfilename);<br>?>$im = new imagick($filepath.$filename);
到这一步就会报错:
uncaught exception 'imagickexception' with message 'unable to open image `f:哈.tif': no such file or directory @ error/blob.c/openblob/2638' in f:workspace est.php:12
stack trace:
#0 f:workspace est.php(12): imagick->__construct('f:??.tif')
#1 {main}
thrown
------解决方案--------------------
那大哥您就别用中文文件名成不
看这个情况应该是这个包只支持utf-8的文件名,你在linux下跑估计就没什么问题了
------解决方案--------------------
参考一下这个吧
http://s.yanghao.org/program/viewdetail.php?i=91439
------解决方案--------------------
关于中文或其他多字节文件名的问题(仅限windows)
这是php的死症——php不能读取windows里面的unicode文件名,但其他系统可以
因为其他系统的unicode文件名多为utf-8编码,windows是特殊的混合编码
但php可以读取符合本地系统codepage的文件名,例如简体windows读取汉字(常用,限gb2312/gbk以内,如果有unicode extent汉字因为超出936的codepage也不属此列)的文件名没有问题,但为何web的php不行,因为apache……再次无解
所以php处理多字节windows符合本地codepage文件名只能绝对路径方式,处理unicode文件名只能用取巧的方式(短路径)+com,其他函数基本无力









