如何在浏览器中显示大约1000张30 kb的图像?

如何在浏览器中显示大约1000张30 kb的图像?

问题描述:

I am trying to display around 1000 .jpg images of size 30 kb each (in average). Let me show the script first :

<?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>";            
?>

While the number of images is less say around 20, no error occurs and the script works perfectly fine. But as the number exceeds say 200 then "500 Internal Server Error" is coming up. How to cop up with this situation? Please suggest a remedy.

我试图显示大约1000张.jpg图像,每张图片大小为30 kb(平均值)。 让我首先显示脚本: p>

 &lt;?php 
 ini_set('display_errors',1); 
 //数据库连接文件
包含'../  ../lib/config.php'; .n包括'../../lib/opendb.php'; 
nn set_time_limit(9999);  //增加大型上传数据库的执行时间// 
 
 //允许访问页面
 
 $ showandsave = false;  //选择查看并保存图像
 
 
 if(isset($ _ POST ['submit_html'])){
 $ showandsave = true; 
} 
 
 $ reportdatefrom = $ _REQUEST ['  reportdatefrom']; 
 $ reportdateto = $ _REQUEST ['reportdateto']; 
 //为主列表准备常量查询
 $ qry_const =“select”; 
 $ qry_const。=“”。“a.photoname”  ;  
 $ qry_const。=“”。“来自申请人a”;  
 $ qry_const。=“”。“其中a.date_of_admission介于'$ reportdatefrom'和'$ reportdateto'”; 
 
 $ rs = mysql_query($ qry_const)或die(“Error Fetching List:”。mysql_error(  ));  
 
 $ gridsize = 10; 
 $ r = 0; 
 echo“&lt; table&gt;”; 
 while($ row = mysql_fetch_assoc($ rs)){
 + n $ $ r; 
 if  ($ r == 1 ||($ r-1)%$ gridsize == 0)
 echo“&lt; tr&gt;”; 
 echo“&lt; td&gt;&lt; img src ='”。$ row [  'photoname']。“'height ='100px'width ='75px'/&gt;&lt; / td&gt;”; 
 if($ r%$ gridsize == 0)
 echo“&lt; / tr&gt;”  ; 
} 
 echo“&lt; / table&gt;”;  
?&gt; 
  code>  pre> 
 
 

虽然20左右的图像数量较少,但不会发生错误,并且脚本可以正常工作。 但随着数量超过200,那么“500内部服务器错误”即将出现。 如何应对这种情况? 请提出补救建议。 p> div>

A 500 error in PHP generally means the script crashed. You need to know why it crashed.

That can sometimes be found in the web server error log or the php error log. You didn't say what platform (linux / apache / php? windows / iis / php? ) you're running on so it's hard to tell you where to look. Use your favorite search engine to ask for php error log location linux apache or whatever. Then look at the end of the error log.

While you're at it, look for php.ini location linux apache. There's a file called php.ini containing system limits.

I guess you are running out of time or RAM. PHP generally won't let you arbitrarily increase the time limit in the way you're trying: set_time_limit (9999). The maximum time you can't exceed is the max_execution_time setting in the php.ini file. You may need to change it there.

Your PHP script may also be running out of memory. You'll need to change the memory_limit setting to fix that.

In the comments somebody mentioned the security danger of using the mysql_ interface. That person was not kidding. From comments in your code it looks like your site handles university applications. Now, nobody would dream of cracking a site like that. Would they? Would they? Be careful. Don't rely on a large institution's firewall.