Home > Backend Development > PHP Tutorial > 为什么fopen无法打开文件

为什么fopen无法打开文件

PHPz
Release: 2020-09-05 09:47:42
Original
4571 people have browsed it

fopen无法打开文件是因为错误使用了中文的引号,其解决办法就是将引号改为英文状态下即可,具体代码为“$handle=fopen($filename,”w”);$handle=fopen($filename,”a”);”。

为什么fopen无法打开文件

为什么fopen无法打开文件?

具体问题:

php语言:文件存在且可写,但为什么fopen无法打开文件

  <html>
    <meta http-equiv="Content-Type" content="text/html ;charset= utf-8"/ >
    <body>
<?php
    $filename="./zhufu.txt";
    if(file_exists($filename))
    {
        echo("file: $filename exists\n");
    }
    else
    {
        echo("Can not open file: $filename.\n");
        return 0;
    }
    if(is_writeable($filename))
    {
        echo ("$filename is writeable");
    }
    else
    {
        echo ("$filename is not writeable");
    }
    $wr=“一等奖:王轮”;
    $wr1=“二等奖:张静,李丽”;
    $wr2=“三等奖:赵无,丁一,王六”;
    $handle=fopen($filename,”w”);
    if($handle==false)
    {  echo "不能打开文件";
        exit;
    }
    fwrite($handle,$wr);
    fclose($handle);
    $handle=fopen($filename,”a”);
    fwrite($handle,$wr1);
    fwrite($handle,$wr2);
    fclose($handle);
?>
</body>
</html>
Copy after login

解决办法:

$handle=fopen($filename,”w”);
$handle=fopen($filename,”a”);
Copy after login

错误使用了中文的引号,我测了下,改为英文就好了。

$handle=fopen($filename,"w");
$handle=fopen($filename,"a");
Copy after login

更多相关技术文章,请访问PHP中文网

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template