代码如下:
if( false == (file_get_contents($jsonaddress)))
{
//error
print ('Error with stream, getting file instead !<br />');
$jsonaddress = 'listedesodeurs.txt';
}
else
{
//noerror
print ('Sucessfully GET data from JSON stream<br />');
$jsoncontent = file_get_contents($jsonaddress);
$size = file_put_contents('listedesodeurs.txt', $jsoncontent);
echo ('Making backup of stream in file : '.round(($size/1024),0).' KB <br />');
}
当 file_get_contents = true(无错误)时,一切正常 当 file_get_contents = false 时,我只是在屏幕上收到大错误消息...我只是想测试它,而不是执行它!
怎么做?
这是错误信息:
[function.file-get-contents]: failed to open stream: Inappropriate ioctl for device in
最佳答案
快速方法:
if( false == (@file_get_contents($jsonaddress)))
'@' 抑制错误。
一个可能更好的方法是只测试:
if (! file_exists($jsonaddress)){
可能会做你想做的事(看看你是否能得到流,但如果失败则简单地返回 false)...但我不确定它的效果如何。 (最近没有用 fopen 包装器尝试过)
关于php - 静默捕获php "file_get_contents"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1507224/