Image upload-php upload Chinese name picture failed?

Source: Internet
Author: User
I have a program inside a PHP upload image function, but placed on the server upload the Chinese name of the picture, the picture can not be displayed, see the directory of the picture, is uploaded after the image of the directory is garbled. Here's my code, I don't know what went wrong

' Public Function _upload () {

    $type = Trim ($_post[' uptype ');    $callback = Trim ($_post[' upcallback ');        if ($type = = ' image ') {$ext = Getfileext ($_files[' upfile ' [' name ']); if (!file_exists (dir_upload. ')        /images/'. Date ("YMD")) {MakeDir (dir_upload, '/images/'. Date ("YMD")); if ($ext = = ' jpg ' | | $ext = = ' png ' | | $ext = = ' gif ' | | $ext = = ' Doc ' | | $ext = = ' txt ' | | $ext = = ' pdf ' | | {$upfile = dir_upload. ') /images/'. Date ("Ymd"). ' /'. Date ("his"). '            _ '. Iconv ("gb2312", "UTF-8", $_files[' upfile ' [' name ']); $upfilepath = '/images/'. Date ("Ymd"). ' /'. Date ("his"). '            _ '. Iconv ("gb2312", "UTF-8", $_files[' upfile ' [' name ']); $upfileurl = Url_upload. ' /images/'. Date ("Ymd"). ' /'. Date ("his"). '            _ '. Iconv ("gb2312", "UTF-8", $_files[' upfile ' [' name ']);            Move_uploaded_file ($_files[' upfile ' [' tmp_name '], $upfile);            $FILECG = Trim ($_post[' FILECG ');            if (! $filecg) {$FILECG = 1;            } if ($callback) {    Echo ';        } die (); }} "echo";

All I use in my HTML is UTF-8 '

How can I change this to upload Chinese file name pictures?
My server is Win2003 is not because the server win2003 is GBK relationship?

Reply content:

I have a program inside a PHP upload image function, but placed on the server upload the Chinese name of the picture, the picture can not be displayed, see the directory of the picture, is uploaded after the image of the directory is garbled. Here's my code, I don't know what went wrong

' Public Function _upload () {

    $type = Trim ($_post[' uptype ');    $callback = Trim ($_post[' upcallback ');        if ($type = = ' image ') {$ext = Getfileext ($_files[' upfile ' [' name ']); if (!file_exists (dir_upload. ')        /images/'. Date ("YMD")) {MakeDir (dir_upload, '/images/'. Date ("YMD")); if ($ext = = ' jpg ' | | $ext = = ' png ' | | $ext = = ' gif ' | | $ext = = ' Doc ' | | $ext = = ' txt ' | | $ext = = ' pdf ' | | {$upfile = dir_upload. ') /images/'. Date ("Ymd"). ' /'. Date ("his"). '            _ '. Iconv ("gb2312", "UTF-8", $_files[' upfile ' [' name ']); $upfilepath = '/images/'. Date ("Ymd"). ' /'. Date ("his"). '            _ '. Iconv ("gb2312", "UTF-8", $_files[' upfile ' [' name ']); $upfileurl = Url_upload. ' /images/'. Date ("Ymd"). ' /'. Date ("his"). '            _ '. Iconv ("gb2312", "UTF-8", $_files[' upfile ' [' name ']);            Move_uploaded_file ($_files[' upfile ' [' tmp_name '], $upfile);            $FILECG = Trim ($_post[' FILECG ');            if (! $filecg) {$FILECG = 1;            } if ($callback) {    Echo ';        } die (); }} "echo";

All I use in my HTML is UTF-8 '

How can I change this to upload Chinese file name pictures?
My server is Win2003 is not because the server win2003 is GBK relationship?

I've thought of a way,
is to replace the text
$upfilepath = '/images/'. Date ("Ymd"). ' /'. Date ("his"). Preg_replace (' [^a-z0-9-_.] i ', ' ', $_files ' upfile ');

Although the picture can be displayed, but very reluctant

This is related to the HTTP protocol. Before uploading, grab a bag to see if your program is GBK or Utf-8-based. Confirm and then go to the corresponding iconv.

Is the server Linux? See if it supports Chinese

  • 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.