tmpfile()函数不起作用

时间:2017-03-09 22:52:46

标签: php xampp fopen temporary-files fclose

我写了一个如下所示的代码。

<?php

$temp = tmpfile();
fwrite($temp, "writing to tempfile");
fseek($temp, 0);
echo fread($temp, 1024);
fclose($temp);

?>

但是这段代码在浏览器上给了我这个错误。

  

警告:fwrite()要求参数1为资源,第4行的/Applications/XAMPP/xamppfiles/htdocs/test.php中给出布尔值   警告:fseek()要求参数1为资源,第5行的/Applications/XAMPP/xamppfiles/htdocs/test.php中给出布尔值   警告:fread()要求参数1为资源,在第6行的/Applications/XAMPP/xamppfiles/htdocs/test.php中给出布尔值   警告:fclose()要求参数1为资源,第7行的/Applications/XAMPP/xamppfiles/htdocs/test.php中给出布尔值

如果我使用fopen()代替tmpfile(),则效果很好 我不知道它为什么不起作用。

如果你对此有所了解,请问教我,

*顺便说一下,我使用XAMPP。

1 个答案:

答案 0 :(得分:0)

检查

sys_get_temp_dir() 

返回并确保该文件夹是可写的。