教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 file_get_contents 中文路径报错问题解决

file_get_contents 中文路径报错问题解决

发布时间:2017-12-12   编辑:jiaochengji.com
教程集为您提供file,get,contents 中文路径报错问题解决等资源,欢迎您收藏本站,我们将为您提供最新的file,get,contents 中文路径报错问题解决资源
file_get_contents如果文件或者路径是中文就会出现[function.file-get-contents]: failed to open stream: No such file or directory,这个是编码问题,Windows中是使用gbk中文编码的,而PHP文件一般都是用utf-8格式保存的了。中文地址获取之前做一次iconv('utf-8', 'gbk', $address)就没有问题了

解决file_get_contents遇到中文文件名无法打开问题

比如:受访页面_20151202-20151202.csv

file_get_contents(受访页面_20151202-20151202.csv)就会报错

[function.file-get-contents]: failed to open stream: No such file or directory

改成不用包含中文的文件名路径就可以。

原因:

编码问题,Windows中是使用gbk中文编码的,而PHP文件一般都是用utf-8格式保存的了。中文地址获取之前做一次iconv('utf-8', 'gbk', $path)就没有问题了。

<?php
    $path='/baidu/受访页面_20151203-20151203.csv';
    $path=iconv('utf-8', 'gbk', $path);
    $content=  file_get_contents($path);
    echo $content;
?>

您可能感兴趣的文章:
file_get_contents 中文路径报错问题解决
PHP Warning: file_get_contents failed to open stream解决办法
安装MYSQL-PYTHON包报错mysql_config not found解决办法
如何解决python -v 报错问题
电脑IE8浏览器下载安装网银助手时报错
php命令行下相对路径问题的解决方法
MAC本地安装Ghost提示错误原因分析 MAC本地安装Ghost提示错误解决办法
php中file_get_contents 出现HTTP request failed! ...
linux中PHP dirname(__FILE__)路径问题解决
访问php报404错误的原因

[关闭]
~ ~