PHP 读取文件返回 NULL
PHP readfile returning NULL
任何人都可以帮助读取文件 returning null。根据文档,错误时应该 return false,为什么它给出 null 作为响应。
http://php.net/manual/en/function.readfile.php
该文件存在于路径中,并且还设置了权限。页面的 http 响应是 200 OK。
$fileout = "/path/to/image/image.jpg";
if( file_exists( $fileout ) ) {
/* We already have a resized image
* So send the file to the browser */
switch(strtolower($ext))
{
case ".gif":
header ("Content-type: image/gif");
readfile($fileout);
break;
case ".jpg":
header ("Content-Type: image/jpeg");
readfile($fileout);
break;
case ".png":
header ("Content-type: image/png");
readfile($fileout);
break;
}
}
相同的代码在不同的服务器 (localhost) 上工作正常,请建议我应该点击哪里来解决这个问题。
最后我发现问题是 readfile function was disabled in server (php.ini)。 php.ini "disable_functions" 中有 php 设置,我们可以在其中指定需要禁用的功能列表。在我的例子中,readfile 列在这里,当我删除它时它似乎工作。
PHP有很多函数,如果使用不当,可以用来破解你的服务器。您可以使用 disable_functions 指令在 php.ini 中设置函数列表。该指令允许您出于安全原因禁用某些功能。它采用逗号分隔的函数名称列表。
有关详细信息,请参阅 http://php.net/manual/en/ini.core.php#ini.disable-functions
任何人都可以帮助读取文件 returning null。根据文档,错误时应该 return false,为什么它给出 null 作为响应。
http://php.net/manual/en/function.readfile.php
该文件存在于路径中,并且还设置了权限。页面的 http 响应是 200 OK。
$fileout = "/path/to/image/image.jpg";
if( file_exists( $fileout ) ) {
/* We already have a resized image
* So send the file to the browser */
switch(strtolower($ext))
{
case ".gif":
header ("Content-type: image/gif");
readfile($fileout);
break;
case ".jpg":
header ("Content-Type: image/jpeg");
readfile($fileout);
break;
case ".png":
header ("Content-type: image/png");
readfile($fileout);
break;
}
}
相同的代码在不同的服务器 (localhost) 上工作正常,请建议我应该点击哪里来解决这个问题。
最后我发现问题是 readfile function was disabled in server (php.ini)。 php.ini "disable_functions" 中有 php 设置,我们可以在其中指定需要禁用的功能列表。在我的例子中,readfile 列在这里,当我删除它时它似乎工作。
PHP有很多函数,如果使用不当,可以用来破解你的服务器。您可以使用 disable_functions 指令在 php.ini 中设置函数列表。该指令允许您出于安全原因禁用某些功能。它采用逗号分隔的函数名称列表。
有关详细信息,请参阅 http://php.net/manual/en/ini.core.php#ini.disable-functions