function.fetch plugin bug?
| From: | Jeff Clark | Date: | Mon, 06 May 2002 12:21:27 +0000 |
| Subject: | function.fetch plugin bug? | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-4061@lists.php.net to get a copy of this message | ||
When using:
{fetch file="blah.html" assign="blah"}
and the file "blah.html" does not exist, I get a crapload of errors:
feof(): supplied argument is not a valid File-Handle
fgets(): supplied argument is not a valid File-Handle
Because there is no sanity checking when safe mode is _off_. Did not test
with safe mode on, but I patch both routines just to be safe.
Enjoy!
--
Jeff Clark
--- plugins.original/function.fetch Mon May 6 05:02:12 2002
+++ plugins.fixed/function.fetch.php Mon May 6 05:01:24 2002
@@ -35,11 +35,16 @@
}
// fetch the file
$fp = fopen($file,'r');
+ if($fp) {
while(!feof($fp)) {
$content .= fgets ($fp,4096);
}
fclose($fp);
} else {
+ $smarty->_trigger_plugin_error("fetch unable to
open '$file'");
+ return;
+ }
+ } else {
// not a local file
if(preg_match('!^http://!i',$file)) {
// http fetch
@@ -195,10 +200,16 @@
} else {
// ftp fetch
$fp = fopen($file,'r');
+ if($fp) {
while(!feof($fp)) {
$content .= fgets ($fp,4096);
}
fclose($fp);
+ } else {
+ $smarty->_trigger_plugin_error("fetch
unable to open '$file'");
+ return;
+ }
+
}
}