472,989 Members | 2,833 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,989 software developers and data experts.

Chinese filenames

Hi everyone,

Firstly, I would like to know if you can open chinese filenames under
win2000 using PHP 5.0? I have a file named *国.php, and try to open it
using
fopen(‘*国.php','r');. I save the source file as UTF-8. I get the
error:

Warning: fopen(*国.php) [function.fopen]: failed to open stream: No
such file or directory in E:\Translation\Website
Development\webroot\testing\zhongguo.php on line 8

I have triple checked that the file exists. Changing the source code
encoding to 'Unicode (UCS-2)' leads to no output in the browser
window.

Does PHP even support opening chinese filenames?

Secondly, I'm having some trouble accessing filenames with chinese
characters that have been uploaded via HTTP. I'm using PHP 5 and
Apache 2.2. When I
attempt to upload a file with chinese filenames, the file name gets
mutated into dashes, pretty much matching the behaviour described at
'http://gallery.menalto.com/node/57709'. However, I need the original
filename (to store in a DB). The post on the manual website by
kweechang at yahoo dot com at http://au3.php.net/manual/en/
features.file-upload.php describes using javascript to set a hidden
field. This would work fine but for now I'm trying not to resort to
javascript on my webpage. Does anyone know how the original filename
can be retrieved without using javascript? Maybe there is a setting in
Apache?

Thanks

Taras

Jan 29 '07 #1
2 5330
"Taras_96" <ta******@gmail.comwrote:
Does PHP even support opening chinese filenames?
I don't know how exactly fopen() handles strings containing characters
other that ASCII, but it is better to not rely on the underlying file
system for portability reasons. Always use simple ASCII characters. For
files uploaded via HTTP, store their original name in a DB table properly
created to support UTF-8.
Secondly, I'm having some trouble accessing filenames with chinese
characters that have been uploaded via HTTP. I'm using PHP 5 and
Apache 2.2. When I
attempt to upload a file with chinese filenames, the file name gets
mutated into dashes, pretty much matching the behaviour described at
'http://gallery.menalto.com/node/57709'. However, I need the original
filename (to store in a DB). The post on the manual website by
kweechang at yahoo dot com at http://au3.php.net/manual/en/
features.file-upload.php describes using javascript to set a hidden
field. This would work fine but for now I'm trying not to resort to
javascript on my webpage. Does anyone know how the original filename
can be retrieved without using javascript? Maybe there is a setting in
Apache?
0. Ensure your PHP script be properly UTF-8 encoded. This is important
if it contains some literal string.

1. Ensure the page containing the FORM be UTF-8 encoded. For example:

<?php
header("Content-Type: text/html; charset=UTF-8");
?>
<html><body>
<FORM method=post
enctype="multipart/form-data"
accept="image/gif,image/png,image/jpeg,image/pjpeg"
action="the-program-receiving-the-data.php">
Photo (accepted GIF, PNG o JPEG, max 500 KB):
<INPUT type=hidden name=MAX_FILE_SIZE value=512000>
<INPUT type=file name=PHOTO size=50 maxlength=512000><p>
<INPUT type=submit name=save_button value=Save>
</FORM>
</body></html>

The file name returned from the client will have the same encoding of the
page containing the FORM, that is UTF-8.

2. The name of the file can be acquired as a UTF-8 string:

$field = "PHOTO";

if( ! isset($_FILES) || ! isset($_FILES[$field]) )
die("No file uploaded.");

$error = (int) $_FILES[$field]['error'];
$name = (string) $_FILES[$field]['name'];
$type = (string) $_FILES[$field]['type'];
$size = (int) $_FILES[$field]['size'];
$tmp_name = (string) $_FILES[$field]['tmp_name'];

if( $error !== 0 )
die("Upload error code $error.");

# Here: check actual UTF-8 encoding and max length for $name.
# Here: check actual MIME $type against the allowed MIME types.
# Here: check actual $size limit.
# Here: store the file $tmp_name in a proper place with a proper name.

3. Ensure the DB you are using really has support for UTF-8. For example,
retrieve the file name once saved and compare it with the string just
acquired from the POST.

4. Don't try to save the file under the underlying file system using the
name provided by the client, always use some other identifier, for example
the primary key assigned by the DB (typically a simple number). Since the
file name now contain only simple ASCII chars, fopen() should not give
problems.

Best regards,
___
/_|_\ Umberto Salsi
\/_\/ www.icosaedro.it

Jan 29 '07 #2
Hey Umberto,
Does PHP even support opening chinese filenames?
I don't know how exactly fopen() handles strings containing characters
other that ASCII, but it is better to not rely on the underlying file
system for portability reasons. Always use simple ASCII characters. For
files uploaded via HTTP, store their original name in a DB table properly
created to support UTF-8.
I actually thought of doing this, but was wondering if PHP could in
fact do it. Never mind, I'll go along with your suggestion.

As for the file names after uploading, I had done everything you
suggested. I noticed that after choosing the filename in Firefox 1.5,
the filename got mangled in the text input section of the file input
(where the filename goes after you choose a file when browsing)! I
tried it on IE 6 and it worked correctly!! This implies to me that
there might be a bug in FF. I'll file a bug report on mozilla and see
what happens.

Taras
Jan 30 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Kobi Lurie | last post by:
Hello all, I'm trying to make a simple script beginner level script, with just functions. it uses the functions: file_get_contents substr taking into an array the text substr took then...
4
by: Knackeback | last post by:
Hi, I wrote a XML file with GNU emacs 21.2.2 and with chinese character content encoded in UTF-8. I wrote something like: <?xml version="1.0" encoding="UTF-8"?> <test> <chinese></chinese>...
6
by: Zhang Weiwu | last post by:
Hello. I am working with a php software project, in it (www.egroupware.org) Chinese simplified locate is "zh" while Traditional Chinese "tw". I wish to send correct language attribute in http...
1
by: Anthony Liu | last post by:
I believe that topic related to Chinese processing was discussed before. I could not dig out the info I want from the mail list archive. My Python script reads some Chinese text and then split...
8
by: pabv | last post by:
Hello all, I am having a few issues with encoding to chinese characters and perhaps someone might be able to assist. At the moment I am only able to see chinese characters when displayed as...
12
by: Steven Nagy | last post by:
Hi all, I have to do a website in chinese! Basically I just need to know how to output chinese characters. I am assuming its very easy, but have never done it before. I can however do simple...
12
by: Steve Howell | last post by:
The never-ending debate about PEP 3131 got me thinking about natural languages with respect to Python, and I have a bunch of mostly simple observations (some factual, some anecdotal). I present...
0
by: scriptmann | last post by:
Hi, I'm trying to use os.listdir() to list directories with simplified chinese filenames. However, while I can see the filenames correctly in windows explorer, I am getting ? in the filename...
2
by: Wassy | last post by:
Hi, i have a website which contains both chinese and english content which is stored in a database. Each record in the dB has an english and Chinese field. If a user enters a search string i have...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.