update fetch function with more error checking

This commit is contained in:
mohrt
2002-05-06 14:50:37 +00:00
parent 8ea6a1b835
commit 933fe652e6
2 changed files with 32 additions and 36 deletions

View File

@@ -29,16 +29,16 @@ function smarty_function_fetch($params, &$smarty)
$smarty->_trigger_plugin_error("(secure mode) fetch '$file' is not allowed"); $smarty->_trigger_plugin_error("(secure mode) fetch '$file' is not allowed");
return; return;
} }
if (!@is_readable($file)) { // fetch the file
if($fp = @fopen($file,'r')) {
while(!feof($fp)) {
$content .= fgets ($fp,4096);
}
fclose($fp);
} else {
$smarty->_trigger_plugin_error("fetch cannot read file '$file'"); $smarty->_trigger_plugin_error("fetch cannot read file '$file'");
return; return;
}
// fetch the file
$fp = fopen($file,'r');
while(!feof($fp)) {
$content .= fgets ($fp,4096);
} }
fclose($fp);
} else { } else {
// not a local file // not a local file
if(preg_match('!^http://!i',$file)) { if(preg_match('!^http://!i',$file)) {
@@ -127,12 +127,6 @@ function smarty_function_fetch($params, &$smarty)
return; return;
} }
break; break;
case "cluster_host":
if(!empty($param_value)
&& (gethostbyname($param_value) != $param_value)) {
$server_name = $param_value;
}
break;
default: default:
$smarty->_trigger_plugin_error("unrecognized attribute '".$param_key."'"); $smarty->_trigger_plugin_error("unrecognized attribute '".$param_key."'");
return; return;
@@ -194,11 +188,15 @@ function smarty_function_fetch($params, &$smarty)
} }
} else { } else {
// ftp fetch // ftp fetch
$fp = fopen($file,'r'); if($fp = @fopen($file,'r')) {
while(!feof($fp)) { while(!feof($fp)) {
$content .= fgets ($fp,4096); $content .= fgets ($fp,4096);
}
fclose($fp);
} else {
$smarty->_trigger_plugin_error("fetch cannot read file '$file'");
return;
} }
fclose($fp);
} }
} }

View File

@@ -29,16 +29,16 @@ function smarty_function_fetch($params, &$smarty)
$smarty->_trigger_plugin_error("(secure mode) fetch '$file' is not allowed"); $smarty->_trigger_plugin_error("(secure mode) fetch '$file' is not allowed");
return; return;
} }
if (!@is_readable($file)) { // fetch the file
if($fp = @fopen($file,'r')) {
while(!feof($fp)) {
$content .= fgets ($fp,4096);
}
fclose($fp);
} else {
$smarty->_trigger_plugin_error("fetch cannot read file '$file'"); $smarty->_trigger_plugin_error("fetch cannot read file '$file'");
return; return;
}
// fetch the file
$fp = fopen($file,'r');
while(!feof($fp)) {
$content .= fgets ($fp,4096);
} }
fclose($fp);
} else { } else {
// not a local file // not a local file
if(preg_match('!^http://!i',$file)) { if(preg_match('!^http://!i',$file)) {
@@ -127,12 +127,6 @@ function smarty_function_fetch($params, &$smarty)
return; return;
} }
break; break;
case "cluster_host":
if(!empty($param_value)
&& (gethostbyname($param_value) != $param_value)) {
$server_name = $param_value;
}
break;
default: default:
$smarty->_trigger_plugin_error("unrecognized attribute '".$param_key."'"); $smarty->_trigger_plugin_error("unrecognized attribute '".$param_key."'");
return; return;
@@ -194,11 +188,15 @@ function smarty_function_fetch($params, &$smarty)
} }
} else { } else {
// ftp fetch // ftp fetch
$fp = fopen($file,'r'); if($fp = @fopen($file,'r')) {
while(!feof($fp)) { while(!feof($fp)) {
$content .= fgets ($fp,4096); $content .= fgets ($fp,4096);
}
fclose($fp);
} else {
$smarty->_trigger_plugin_error("fetch cannot read file '$file'");
return;
} }
fclose($fp);
} }
} }