Uploading files via PHP form, UTF file name encoding error

Everything works dandy, except when I upload a file and give it that own name (using a text field in an HTML form). ร…รครถรด - KARL

I created my own file upload / handler / cms for my site and everything works, except when the file is uploaded.

When I look directly into the file upload directory through my FTP program, the file name suddenly. "A ... รƒยครƒยถรƒ '- KARL"

  • I run html5 with <meta charset="UTF-8" /> at the beginning of each page
  • I am coding when writing code with UTF-8 without specification

I tried iconv() , is there something I am missing? I suspect this between the html $_POST['name_of_file'] form and when running the command

 move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_POST['name_of_file']) 

Progress: I actually made "utf8_decode" and now the file is saved as the correct name, it now looks strange on my site, so I need to encode it when I want to display it.

In any case, to get around, you need to type utf8_encode and utf8_decode everywhere?

For others, this message may help: How do I handle user input for invalid UTF-8 characters?

+4
source share
1 answer

PHP file system functions are known to manage non-ASCII names.

I suggest you strip / convert all non-ASCII characters, or if that is not possible, try utf8_[en/de]code .

See also How to handle user input for invalid UTF-8 characters? .

+4
source

All Articles