搜索

首页  >  问答  >  正文

读取新创建的临时文件内容报错的问题

<?php
//创建一个临时文件
$lsfile = tmpfile();

//向里面写入数据
$lsshuju = fwrite($lsfile,'111这里是写入临时文件的数据');

//输出写入情况
echo '向临时文件中写入了' . $lsshuju . '个字符<br>';

//输出临时文件的内容
$shuchu = file_get_contents($lsfile);
echo $shuchu;

//关闭临时文件
fclose($lsfile);
?>


读取内容报错,请问如何读取内容正确?

LIWENLIWEN2790 天前1393

全部回复(1)我来回复

  • ringa_lee

    ringa_lee2017-06-14 21:15:05

    报什么错的

    回复
    0
  • LIWEN

    向临时文件中写入了39个字符 Warning: file_get_contents() expects parameter 1 to be a valid path, resource given in /home/phpcn6peh2pwcun/wwwroot/compile.php(30) : eval()'d code on line 12

    LIWEN · 2017-06-15 09:02:41
    ringa_lee

    报错的是$lsfile这个变量不是有效的路径

    ringa_lee · 2017-06-15 09:14:49
  • 取消回复