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

@@ -28,17 +28,17 @@ function smarty_function_fetch($params, &$smarty)
if (!$resource_is_secure) { if (!$resource_is_secure) {
$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)) {
$smarty->_trigger_plugin_error("fetch cannot read file '$file'");
return;
} }
// fetch the file // fetch the file
$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); fclose($fp);
} else {
$smarty->_trigger_plugin_error("fetch cannot read file '$file'");
return;
}
} 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); fclose($fp);
} else {
$smarty->_trigger_plugin_error("fetch cannot read file '$file'");
return;
}
} }
} }

View File

@@ -28,17 +28,17 @@ function smarty_function_fetch($params, &$smarty)
if (!$resource_is_secure) { if (!$resource_is_secure) {
$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)) {
$smarty->_trigger_plugin_error("fetch cannot read file '$file'");
return;
} }
// fetch the file // fetch the file
$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); fclose($fp);
} else {
$smarty->_trigger_plugin_error("fetch cannot read file '$file'");
return;
}
} 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); fclose($fp);
} else {
$smarty->_trigger_plugin_error("fetch cannot read file '$file'");
return;
}
} }
} }