Re: Hebrew Directory Names
| From: | Tom Worster | Date: | Thu, 28 May 2009 18:37:24 +0000 |
| Subject: | Re: Hebrew Directory Names | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-293314@lists.php.net to get a copy of this message | ||
On 5/28/09 2:06 PM, "Nitsan Bin-Nun" <nitsan@binnun.co.il> wrote:
> i have tried this:
>
> <?php if (!defined('THROUGH_INDEX')) die('Sorry mate!');
>>
>> $default_locale = setlocale(LC_ALL, 'en_US.UTF-8');
>> ini_set('default_charset', 'UTF-8' );
>>
>>
>> $_GET['folder'] =
>>
>> preg_replace("/([\xE0-\xFA])/e","chr(215).chr(ord(\${1})-80)",$_GET['folder']
>> );
>>
>> $dirname =
>> $config['walls_dir'].$_GET['folder']."/".$_GET['filename'];
>>
>>
>> if (!is_file($dirname)) { echo "leave();"; g($dirname);die;}
>>
>
>
> I'm still getting:
>
>> leave();
>>
>> string(56) "/home/nitsanbn/public_html/iphoneia/walls/חלל/008.jpg"
>>
>>
> The preg_replace() above convert the Hebrew chars into UTF8.
> The conversion does work but the file is not recognized as a file, although
> that i can browse it straightly.
why do you think that you need to do any conversion at all?
that preg_replace looks terrifying! how did you come by it? i'm immediately
suspicious that this is the problem.
i googled the code and found people claiming that it translates window-1255
to utf8 (2004, dubious) and iso-8859-1 to utf-8 (2005, dubious).
if you know that the browser is sending the GET variable 'folder' in a known
encoding other than utf8, why not convert it with mb_convert_encoding or
iconv?
alternatively, force the user agent to send it in utf8 by sending the form
as utf 8 (send header('Content-Type: text/html; charset=utf-8'), and use
accept-charset="utf-8" in the form tag) and don't convert. then you can
avoid all conversions.
> I'm afraid that I don't have access to the php.ini, since it's a shared
> hosting, do you know if hostgator gives access to php.ini or let you changes
> it's values?
i have no idea. but i imagine it is sufficient to use ini_set().