move_uploaded_file … utf8

Questionsmove_uploaded_file … utf8
Benjamin asked 5 years ago

Hi,

I'm trying to upload files that have a french accents in their name (like 'éà.txt'). I always have a server error.

Using $destname = iconv('UTF-8', 'CP1252', $name);
the file is now written on the server but I think that the insert in DB doesn't work.
How to fix this ??

Thanks,
Benjamin

4 Answers
Abu Ghufran answered 5 years ago

Before database insert, you might need to set:
mysql_query("SET NAMES 'utf8'");

If you are using v1.5.2 or plus, this is default in mysql usage.

You might also check the database table and field collation, and make sure it is capable of storing utf8 content.

Benjamin answered 5 years ago

Hi,

That doesn't work … I'm using mysql v5.6.16.
For example, I have uploaded the file "aaaéèçààààà.txt". It works fine except that the file I see in the Explorer is named "aaaéèçààààà.txt".
The DB fields contains the correct path ("aaaéèçààààà.txt").

When I try to open it by clicking on the link, it doesn't find the file.
When I renamed it on the Explorer from "aaaéèçààààà.txt" to "aaaéèçààààà.txt", then it works.

In jggrid_dist_php and jggrid_dist_php4, I did this:

$destname = iconv('UTF-8', 'CP1252', $name);
if ( @move_uploaded_file($tmp_name, "$uploads_dir/$destname") )
{
$msg = "$uploads_dir/$name";
} …

the filename is written correctly in the Explorer but I got a "Server Error 500"

… please help !!
Thanks

Benjamin answered 5 years ago

Hi Abu,

… any idea to how can I fix this ?

Thanks,

Abu Ghufran answered 5 years ago

I tested this case, after your patch:

$destname = iconv('UTF-8', 'CP1252', $name);
if ( @move_uploaded_file($tmp_name, "$uploads_dir/$destname") )
{
$msg = "$uploads_dir/$name";
}

It saves file with correct name in folder
Show correct file name in dialog
And save correct name path in database

For error 500, please check apache error log, OR response of update ajax call using firebug.

Your Answer

17 + 19 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?