#26574 [Asn->Csd]: basename() cannot work with Chinese Path name

From: Date: Thu, 22 Jan 2004 09:38:25 +0000
Subject: #26574 [Asn->Csd]: basename() cannot work with Chinese Path name
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-53751@lists.php.net to get a copy of this message
ID: 26574 Updated by: moriyoshi@php.net Reported By: gaoyong at crtvu dot edu dot cn -Status: Assigned +Status: Closed Bug Type: *Directory/Filesystem functions Operating System: Windows 2k SP4 PHP Version: 4.3.4 Assigned To: moriyoshi New Comment: Already fixed in php5-cvs, but not sure whether to merge it to the php4 branch. Previous Comments: ------------------------------------------------------------------------ [2003-12-10 00:55:06] moriyoshi@php.net This problem appears to be caused by the wrong usage of IsDBCSLeadByte(). ------------------------------------------------------------------------ [2003-12-09 22:51:12] gaoyong at crtvu dot edu dot cn Description: ------------ if the parameter of basename() contain Chinese path name like this "e:\²âÊÔ\2.jpg",the function can not work. The HTML contain the path "e:\²âÊÔ\2.jpg" First, I copy the upload temp file from "c:\winnt\temp" to the cache path("d:\oems\....\cach"), Secondly, I parse the HTML content that user submiting,and getting the image "SRC" like "e:\²âÊÔ\2.jpg", third, using basename() to get the filename(2.jpg) but the function return "e:\²âÊÔ\2.jpg" When The path name doesn't contain Chinese Character and space,it can work well. Reproduce code: --------------- function Picstr_handle($s) { ...... $s=stripslashes($s); $tmpImg = explode("SRC=\"",$s); $tmpImg1 = explode("\"></IMG>",$s); ...... for ($i =1; $i< count($tmpImg); $i++) { $sourcefilepath[$i] = explode("\"></IMG>",$tmpImg[$i]); $destfilepath[$i] = $ServerRootPath."/exam/image/".$QuestionPathName[$QuestionType]; if (!is_dir($destfilepath[$i])) {mkdir($destfilepath[$i],0);} $destfilepath[$i] .= "/".$InputUser; if (!is_dir($destfilepath[$i])) {mkdir($destfilepath[$i],0);} $destfilepath[$i] .= "/".date("Ymd",time()); if (!is_dir($destfilepath[$i])) {mkdir($destfilepath[$i],0);} $destfilepath[$i] .= "/" .substr(md5(basename($sourcefilepath[$i][0])),2,8) .substr(basename($sourcefilepath[$i][0]),strlen(basename($sourcefilepath[$i][0]))-4,4); $sourcefilepath[$i][0] =$ServerRootPath."/exam/image/cache/".basename($sourcefilepath[$i][0]); if(!is_file($destfilepath[$i])) { if (!copy($sourcefilepath[$i][0],$destfilepath[$i])) { echo "¸´ÖƵµ°¸" .$sourcefilepath[$i][0]." ʧ°Ü...<br>" ;break;exit(); } if (is_file($sourcefilepath[$i][0])) {unlink($sourcefilepath[$i][0]);} } } Expected result: ---------------- Warning: copy(D:/oems/teachingcenter_test/webroot/exam/image/cache/E:\²âÊÔ\2.JPG): failed to open stream: Invalid argument in D:\oems\teachingcenter_test\webroot\exam\datainput\insert.html on line 77 ¸´ÖƵµ°¸D:/oems/teachingcenter_test/webroot/exam/image/cache/E:\²âÊÔ\2.JPG ʧ°Ü... Actual result: -------------- no warning ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=26574&edit=1

« previous php.bugs (#53751) next »