我试图显示大约 1000 个 .jpg 图像,每个图像大小为 30 kb(平均)。让我先展示一下脚本:
<?php
ini_set('display_errors', 1);
// database connection files
include '../../lib/config.php';
include '../../lib/opendb.php';
set_time_limit (9999); // to increase execution time for large upload database//
// allow access to page
$showandsave = false; // choosen to view and save the images
if(isset($_POST['submit_html'])){
$showandsave = true;
}
$reportdatefrom = $_REQUEST['reportdatefrom'];
$reportdateto = $_REQUEST['reportdateto'];
// Prepare Constant Query for Master List
$qry_const = "select";
$qry_const .= " "."a.photoname";
$qry_const .= " "."from applicants a";
$qry_const .= " "."where a.date_of_admission between '$reportdatefrom' and '$reportdateto'";
$rs = mysql_query($qry_const) or die("Error Fetching List : ".mysql_error());
$gridsize = 10;
$r = 0;
echo "<table>";
while($row = mysql_fetch_assoc($rs)){
++$r;
if($r == 1 || ($r-1)%$gridsize == 0)
echo "<tr>";
echo "<td><img src='".$row['photoname']."' height='100px' width='75px'/></td>";
if($r%$gridsize == 0)
echo "</tr>";
}
echo "</table>";
?>
虽然图像数量少于 20 个左右,但没有发生错误,并且脚本运行得很好。但当数量超过 200 时,就会出现“500 内部服务器错误”。如何应对这种情况?请提出补救措施。
最佳答案
PHP 中的 500
错误通常意味着脚本崩溃。您需要知道为什么它崩溃了。
有时可以在 Web 服务器错误日志或 PHP 错误日志中找到。您没有说您正在运行什么平台(linux/apache/php?windows/iis/php?),因此很难告诉您在哪里查看。使用您最喜欢的搜索引擎询问 php 错误日志位置 linux apache
或其他内容。然后查看错误日志的末尾。
当您执行此操作时,请查找php.ini location linux apache
。有一个名为 php.ini
的文件,其中包含系统限制。
我猜你的时间或内存已经用完了。 PHP 通常不会让您按照您尝试的方式任意增加时间限制:set_time_limit (9999)
。您不能超过的最长时间是 max_execution_time setting in the php.ini
file 。您可能需要在那里更改它。
您的 PHP 脚本也可能内存不足。您需要更改 memory_limit
setting来解决这个问题。
在评论中有人提到使用mysql_
接口(interface)的安全危险。那个人没有开玩笑。从代码中的注释来看,您的网站似乎处理大学申请。现在,没有人会梦想破解这样的网站。他们会吗?他们会吗?当心。不要依赖大型机构的防火墙。
关于php - 如何在浏览器中显示大约 1000 张每个 30 kb 的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38026868/