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 SkipVought 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
0
0
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
 
Looks like this code's a bit over my head! I'm relatively new to uploading files... If anyone could help, that would be great!!! Here's the fix they mention:

Code:
// look for entities in the file name, and if found try to convert the filename to UTF-8
$filename = $attachmentinfo['filename'];
if (preg_match('~&#([0-9]+);~', $filename)){
    if (function_exists('iconv')){
        $filename = @iconv($stylevar['charset'], 'UTF-8//IGNORE', $filename);
    }

    $filename = preg_replace('~&#([0-9]+);~e',"convert_int_to_utf8('\\1')",$filename);
    $filename_charset = 'utf-8';
} else {
    $filename_charset = $stylevar['charset'];
}

$filename = preg_replace('#[\r\n]#', '', $filename);

// Opera and IE have not a clue about this, mozilla puts on incorrect extensions.
if (is_browser('mozilla')){
    $filename = "filename*=" . $filename_charset . "''" . rawurlencode($filename);
} else {
    // other browsers seem to want names in UTF-8
    if ($filename_charset != 'utf-8' AND function_exists('iconv')){
        $filename = @iconv($filename_charset, 'UTF-8//IGNORE', $filename);
    }

    if (is_browser('opera')){
        // Opera does not support encoded file names
        $filename = 'filename="' . str_replace('"', '', $filename) . '"';
    } else {
        // encode the filename to stay within spec
        $filename = 'filename="' . rawurlencode($filename) . '"';
    }
}

if ($extension != 'txt'){
    header("Content-disposition: inline; $filename");
    header('Content-transfer-encoding: binary');
}

RISTMO Designs: Rockwall Web Design
Arab Church: Arabic Christian Resources
Genuine Autos: Kaufman Chevrolet & Pontiac Dealer
Rick Morgan's Official Website
 
Does that code snippet do any good? It seems incomplete to me.

Where is $attachmentinfo initialized? Where is is_browser() defined?



Want the best answers? Ask the best questions! TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top