Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Upload Image with Filename in Different Language...

Status
Not open for further replies.

RISTMO

Programmer
Nov 16, 2001
1,259
US
Hey,

I have an image upload script that works fine -- but only when the filename of the image being uploaded contains English characters.

When I try to upload an image named ??????.jpg for example (the filename has Arabic characters), the script doesn't work, and the filesize of the uploaded image is 0.

This is a problem as the site runs primarily in Arabic. I'm sure there's got to be a way to accept an image upload where the filename is in a different character set.

I can post the current script if that would help (it's kind of long). Any ideas?

Rick

RISTMO Designs: Rockwall Web Design
Arab Church: Arabic Christian Resources
Genuine Autos: Kaufman Chevrolet & Pontiac Dealer
Rick Morgan's Official Website
 
I've found nothing that says it's not possible. Nor have I found anything that specifically says it has been done.

Out of curiosity, isn't Arabic a right-to-left language?



Want the best answers? Ask the best questions! TANSTAAFL!
 
Yes, it is. I'm sure it's been done before--I'm just not sure if it's been done on a machine that doesn't have Arabic installed on the OS itself.

I was going to get a dedicated server with Liquid Web, but they won't support it if I get Arabic installed, which kind of defeats having it fully managed in the first place.

It seems to me like the file's being uploaded regardless, and there's just something making it inaccessible once it's on the server. But it seems like the information contained in the file is still being sent, so there should still be a way to capture it somehow...

I'd really like to avoid installing Arabic if that's possible.

RISTMO Designs: Rockwall Web Design
Arab Church: Arabic Christian Resources
Genuine Autos: Kaufman Chevrolet & Pontiac Dealer
Rick Morgan's Official Website
 
i can't believe it's got insoluble!

not sure that any of this will work as i am not using an arabic OS myself but:
* make sure that the form uses the lang tag
* set the encoding to multipart
* on the server DONT try to save the file with the original file name - instead save it with a unique id and then store a lookup value somewhere in an application that you know can take unicode (i.e. mysql with the db set up with the right charset).
 
Here's a small test script:

Code:
<?
if(isset($_REQUEST["submitter"])){
	echo $_FILES['imgfile']['name'] . "<br />";
	echo $_FILES['imgfile']['tmp_name'] . "<br />";
	echo $_FILES['imgfile']['size'] . "<br />";
}
?>
<form action="<?= $PHP_SELF ?>" method="post" enctype="multipart/form-data">
<table>
	<tr><td colspan="2"><h1>Upload Image</h1></td></tr>
	<tr>
		<td valign="top">Image (Must be JPG):</td>
		<td valign="top"><input type="file" name="imgfile"></td>
	</tr>
	<tr>
		<td valign="top"></td>
		<td valign="top"><input type="submit" name="submitter" value="Upload Image" /></td>
	</tr>
</table>
</form>

When I upload an image with an English filename:
House Cricket diag.jpg
/tmp/phpN8eG15
32036

When I try to upload an image with an Arabic filename:
______.jpg
/tmp/phpouDYJP
0


I don't know if this will show up successfully, but you can copy and paste the next line into the filename of a jpg image on your computer:
??????.jpg


You can test out the script above here with English and Arabic filenames to see what I mean:


Thanks,
Rick

RISTMO Designs: Rockwall Web Design
Arab Church: Arabic Christian Resources
Genuine Autos: Kaufman Chevrolet & Pontiac Dealer
Rick Morgan's Official Website
 
I can't figure out how to copy the filename and use is to rename a file on my filesystem.

In my Tek-Tips user profile is an obfuscated email address. Could you email as an attachment a file with an Arabic filename to me there? It can be a two-byte text file, so long as it has an Arabic filename.



Want the best answers? Ask the best questions! TANSTAAFL!
 
Greetings,

I am interested to learn if and when any solutions to this problem arise. I am currently developing a website and several complimentary applications which are all multilingual. I know that this issue will come up when everything goes live and would like to deal with it now instead of later.

Thanks,
Itshim
 
RSTMO:
Thanks, I got your email. But the filenames had been transformed into something else.

I don't know what to do from here. Unfortunately, I don't have a machine where I could play to see what I could come up with.



Want the best answers? Ask the best questions! TANSTAAFL!
 
[Assume another email where RSTMO explained to me how to use a line in an attached text file to copy-and-paste a filename to Windows Explorer]

RSTMO:
That got it. I now have on my filesystem a file with an Arabic filenname.

But....

When, using this script:

Code:
<?php
print '<html><body>';

if (isset ($_FILES['thefile']))
{
	print '<pre>';
	print_r ($_FILES);
	print '</pre>';
}
else
{
	print '
	<form method="post" enctype="multipart/form-data" action="show_files.php">
		<input type="file" name="thefile"><br/>
		<input type="submit">
	</form>';
}
print '</body></html>';
?>

I upload the file with the Arabic-language filename, I get good data:

[tt]Array
(
[thefile] => Array
(
[name] => ??????.txt
[type] => text/plain
[tmp_name] => /tmp/phpPYnaao
[error] => 0
[size] => 9
)

)[/tt]

This is on a LAMP (FC3/2.0.53/5.0.15/5.1.1) box, testing with both Opera and IE. What is your environment?



Want the best answers? Ask the best questions! TANSTAAFL!
 
Hmm, that's interesting (and encouraging). This is the result I'm getting with the script you posted (same issue as before -- filesize = 0).

Array
(
[thefile] => Array
(
[name] => ______.jpg
[type] => application/octet-stream
[tmp_name] => /tmp/phpMlsvNf
[error] => 0
[size] => 0
)

)


I set up an account on my server and emailed you the login info to see if you can figure anything out. Thanks a bunch!

RISTMO Designs: Rockwall Web Design
Arab Church: Arabic Christian Resources
Genuine Autos: Kaufman Chevrolet & Pontiac Dealer
Rick Morgan's Official Website
 
I'm assuming this is the environment info you want to know:

SERVER_SOFTWARE Apache/1.3.33 (Unix) mod_ssl/2.8.22 OpenSSL/0.9.7a PHP/4.3.10 mod_perl/1.29 FrontPage/5.0.2.2510

Perhaps my issue is Apache 1.3 -- or maybe I need to get PHP 5.0. But I'm starting to wonder if this is all because my software's old. If so, upgrading would fix the problem, and my current script should run just fine. Of course I'm just guessing, but I'm pretty sure your system isn't specifically set up to support Arabic, so if it works on yours, I should be pretty safe upgrading without needing Arabic installed.

Rick

RISTMO Designs: Rockwall Web Design
Arab Church: Arabic Christian Resources
Genuine Autos: Kaufman Chevrolet & Pontiac Dealer
Rick Morgan's Official Website
 
You're right -- neither my workstation OS (Windows XP) nor my server OS are set up specifically to support Arabic.

How did you install Apache and PHP? I compiled both from source tarball -- that could make a difference, too.



Want the best answers? Ask the best questions! TANSTAAFL!
 
Apache and PHP came pre-installed with the system (I just pay a monthly fee for the server).

The server I'm planning to get comes with Cent OS instead of Fedora, but I really don't think that difference would make or break something like this. I think I'm going to go ahead and order it (I'd been delaying cause of the $350 setup fee, wanting to make sure I do it right the first time!).

I'm going to have someone else test it on his server running PHP 5.0 (and most likely a newer version of Apache), and if it works for him, I'm just going to upgrade and not worry about making it work with my current setup. If it doesn't work on his, though, maybe the software version isn't the problem...

Rick

RISTMO Designs: Rockwall Web Design
Arab Church: Arabic Christian Resources
Genuine Autos: Kaufman Chevrolet & Pontiac Dealer
Rick Morgan's Official Website
 
Firefox was (is) the issue.

I just tested it in IE, and the upload script works perfectly!

There's a vBulletin fix for it here:

I'm playing around with it trying to see which parts I need to copy to apply their fix to a non-vbulletin upload script. I'll post the code when I figure it out!

Thanks a bunch guys for all the help! This has been quite an interesting issue!

Rick

RISTMO Designs: Rockwall Web Design
Arab Church: Arabic Christian Resources
Genuine Autos: Kaufman Chevrolet & Pontiac Dealer
Rick Morgan's Official Website
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top