本文介紹了警告 feof() 期望參數(shù) 1 是資源的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
我的錯(cuò)誤日志因以下兩個(gè)錯(cuò)誤而失控
My error logs are getting out of control with the two below errors
warning feof() expects parameter 1 to be resource
和
warning fread() expects parameter 1 to be resource
負(fù)責(zé)的代碼是
<?php
$file = '../upload/files/' . $filex;
header("Content-Disposition: attachment; filename=" . urlencode($file));
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");
header("Content-Length: " . filesize($file));
flush(); // this doesn't really matter.
$fp = fopen($file, "r");
while (!feof($fp)) {
echo fread($fp, 65536);
flush(); // this is essential for large downloads
}
fclose($fp);
?>
我使用此代碼進(jìn)行標(biāo)題下載,但現(xiàn)在它嚇壞了 - 在有人問(wèn)我嘗試過(guò)什么之前,我嘗試了谷歌,但仍然沒(méi)有完全理解錯(cuò)誤消息.
I used this code for header downloads but its freaking out right now - before anyone asks what I have tried, I tried google but still don't fully understand the error message.
推薦答案
fopen 失敗并返回 false.false 不是資源,因此是警告.
fopen fails and returns false. false is not a resource, thus the warning.
在將 $fp 作為類似資源的參數(shù)注入之前,您最好對(duì)其進(jìn)行測(cè)試:
You'd better test $fp before injecting it as a resource-like argument:
if(($fp = fopen($file, "r"))) {
[...]
}
這篇關(guān)于警告 feof() 期望參數(shù) 1 是資源的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!