search

Home  >  Q&A  >  body text

An error occurs when reading the contents of a newly created temporary file

<?php
//Create a temporary file
$lsfile = tmpfile();

//Write data into it
$lsshuju = fwrite($lsfile, '111Here is the data written to the temporary file');

//Output writing situation
echo 'Write ' . $lsshuju . ' characters to the temporary file<br>' ;

//Output the contents of the temporary file
$shuchu = file_get_contents($lsfile);
echo $shuchu;

//Close the temporary file
fclose($ lsfile);
?>


An error is reported when reading the content. How can I read the content correctly?

LIWENLIWEN2718 days ago1342

reply all(1)I'll reply

  • ringa_lee

    ringa_lee2017-06-14 21:15:05

    What is wrong with the report

    reply
    0
  • LIWEN

    39 characters were written to the temporary file 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

    The error reported is that the $lsfile variable is not a valid path.

    ringa_lee · 2017-06-15 09:14:49
  • Cancelreply