File_get_contents read path contains Chinese file name related issues

Source: Internet
Author: User
Tags glob
File_get_contents The Read path contains Chinese file name problems
$data = file_get_contents ($file _names); The path that is pointed to in $file_names contains the Chinese file name in the error [Function.file-get-contents]: failed to open Stream:no such file or directory do not use the Chinese filename can, tangled Ah! You cannot rename a file

------Solution--------------------
$file _names = "d:/My Documents/youku files\download/[live] Wang Feng.-Spring. flv";
$s = file_get_contents ($file _names);
echo strlen ($s);//7216760

There is no question of what you are saying, of course you have to write the file name correctly (including the language code)
------Solution--------------------
The key is your $file the file name in the _names is encoded in the same language as the operating system.
------Solution--------------------
discuss

The key is your $file the file name in the _names is encoded in the same language as the operating system.

------Solution--------------------
See Echo strlen ($data) When you are in Chinese;
------Solution--------------------
Iconv ("Utf-8", "GBK", file_get_contents (' url '));
Can I open the contents of the file by switching to the code of the operating system? You are mainly Chinese path can not open the file, get the content so can't replace it
------Solution--------------------
1. There are no spaces in the file name.
2. Then the coding problem, the file directory to print out to see the check.
------Solution--------------------
Your file name is read with a directory function and does not need to be encoded for conversion
Why not use the Glob function?
The file name read by Scandir does not contain a path, and the file name read by Glob is a path. Can eliminate the hassle of assembling file names
Read suffix available pathinfo ($filename, pathinfo_extension) simple and efficient

Also please inform your PHP version number, the lower version of the possible Chinese file name is invalid. Check it out.
  • 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.