php - while (!feof($handle)) -- Error code to warning information -


http://www.example.com/pageview?test=111&test2=999 -> data loading , working..

189 <?php 190 $handle = @fopen("http://www.example.com". htmlspecialchars($_get["test"]) ."/".     htmlspecialchars($_get["test2"]) .".txt", "r"); 191    while (!feof($handle)) 192 { 193 $buffer = fgets($handle, 4096); 194 195 if (strlen(trim($buffer)) > 0){ 196 197 list($a,$b,$c,$d,$e,$f,$g,$h,$i,$j)=explode(",",$buffer); 198 199 $items[] = array('col1' => $a,'col2' => $b,'col3' => $c,'col4' => $d,'col5' => $e,'col6' => $f,'col7' => $g,'col8' => $h,'col9' => $i,'col10' => $j);  200 } 201 } 202 ?> 

http://www.example.com/pageview?test&test2= -> not loading.. normal error in page..

warning: feof(): supplied argument not valid stream resource in /home/---/public_html/---/---.php on line 191  warning: fgets(): supplied argument not valid stream resource in /home/---/public_html/---/---.php on line 193 

how show warning letter instead of error page?

check return value of fopen. if there error during reading you'll $handle equal false, need pass "stream resource" eof

if($handle === false) {     print 'err found'; } else {    while(!eof($handle)) ... } 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -