mysql-php upload a picture with Chinese name failure problem

Source: Internet
Author: User
Code:

$upfile = ' uploads/'. Rand (0,10000). Date (' Ymdhis '). Iconv ("gb2312", "UTF-8", $_files[' upload ' [' name ']); $upfile is the link address of the uploaded image, stored in the database

The name of the original picture in the link address displayed in the database cannot be displayed, and the image suffix format cannot be displayed.
For example, the database shows the link is: Uploads/34420121102122153android Liao
and the original upload image is: Android development framework. jpg

Reply content:

Code:

$upfile = ' uploads/'. Rand (0,10000). Date (' Ymdhis '). Iconv ("gb2312", "UTF-8", $_files[' upload ' [' name ']); $upfile is the link address of the uploaded image, stored in the database

The name of the original picture in the link address displayed in the database cannot be displayed, and the image suffix format cannot be displayed.
For example, the database shows the link is: Uploads/34420121102122153android Liao
and the original upload image is: Android development framework. jpg

First of all, it must be the coding problem.
You have three places involved in coding problems, there is a conversion between, very likely to be confused, I suggest you all unified UTF8 code

    1. The file name of the upload $_FILES['upload']['name'] . Look at your code, turn this from gb2312 to UTF8, but first to determine if your original file name upload is really gb2312, need to convert, if you do not need to convert.
    2. What is your database format when you deposit it into the database?
    3. What is the format of the display when the database is read out?

Suggest you check these three places, separately print out to see, unified code, can solve the problem

Linux the following files, try not to name in Chinese

Direct

$upfile = ' uploads/'. Rand (0,10000). Date (' Ymdhis ');

What's the use of your file name?

Generally, the way to do this is: rename after uploading, in the server to store the corresponding table in the manner of pairing. Various operating systems store file encoding is different, and program code is a variety of coding, unified Rename storage is the best way.

is the HTML page of your upload form encoding a utf-8? What do you have to do to transcode it once?

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.