Monday, July 27, 2009

Php include file not found error message?

Hi everyone,





My page includes the following line to display the contents of the text file (price.txt):





$%26lt;?php


include("http://www.something.com/pric...


?%26gt;





Everything works great, however; if the text file is unreachable (internet is down, server is down, etc) it displays the following line instead of displaying the text file:





$


Warning: include(http://www.something.com/price.txt) [function.include]: failed to open stream: HTTP request failed!





Warning: include() [function.include]: Failed opening 'http://www.something.com/price.txt' for inclusion (include_path='.;C:\php5\pear')





I would like to make it so that if the text file is unreachable, nothing is displayed at all...no error message...nothing.





Can anyone help me out please?





Thanks in advance :-)

Php include file not found error message?
%26lt;?


@include("http://web.com/price.txt");


?%26gt;





The @ sign before any command / function represses error reporting.
Reply:Note that you can only include remote files, and use is_file with a remotely included file, if allow_url_fopen() is enabled in your PHP installation. It's often disabled since allow_url_fopen() is a security hazard. Report It

Reply:you could use an if else statement to check the file is availabe.. if not you could show an alternative:





example:


$incl = "http://www.something.com/price.txt";


if (is_file("$incl")) {


include($incl);


} else {


// do alternative here


}





hope it helps
Reply:Yes





%26lt;?php





$filePath = 'thepathandfilename'; // put the full path and file name here $_SERVER['DOCUMENT_ROOT'] . '/directory(s)/filename.ext';





if(is_file($filePath)){





include_once($filePath);





}


else{


//if you want to put an error or some other text here


}





?%26gt;





Wow, the answer below is pretty good, shame its a copy of mine, almost verbatim


No comments:

Post a Comment