3

I am trying to upload one excel file by php code. If that excel file contains 200 records then it works fine. But if that excel file contains more than 500 records, then it shows "Internal Server Error" though I set the following:

set_time_limit(10000);
ini_set('memory_limit', '256M');
ini_set('upload_max_filesize', '30M');
ini_set('post_max_size', '200M');
ini_set('max_input_time', 1000);

Also, in the file internally I am doing a lot, read data from excel file and store in an array then again checking from database whether any element is there in the database or not,. If so then remove that particular data. Again for the remaining data, inserting into a table and checking some conditions with for date. And finally with the remaining push in an array. So is there any option to solve this internal server error issue? If so please let me know.

Code is like the following:

    <?php
    ini_set("display_errors", 1);
    set_time_limit(10000);
    ini_set('memory_limit', '256M');
    ini_set('upload_max_filesize', '30M');
    ini_set('post_max_size', '200M');
    ini_set('max_input_time', 1000);
    ?>
    <fieldset style="border:2px solid #60006B;">
      <legend >Upload Excel File</legend>
        <form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
           <input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
           <table width="600">
             <tr>
                <td>Excel File:</td>
                <td><input type="file" name="cur_pic" style="border:1px solid #ccc;" /></td>
             </tr>
             <tr>
                <td colspan="2" style="padding-left:150px;"><input type="submit" value="Upload" name="upload" class="button" /></td>
             </tr>
            </table>
           </form>
        </fieldset>
<?php
  if(isset($_REQUEST['upload'])){
    $image =$_FILES["cur_pic"]["name"];
    $uploadedfile = $_FILES['cur_pic']['tmp_name'];
    if ($image) {

      $filename = stripslashes($_FILES['cur_pic']['name']);

      $extension = getExtension($filename);
      $extension = strtolower($extension);

      if (($extension != "xls") && ($extension != "xlsx")) 
      {

        $change='<div class="msgdiv">Unknown file extension </div> ';
            $errors=1;
       }
       else
       {
         $size=filesize($_FILES['cur_pic']['tmp_name']); 
         move_uploaded_file($_FILES["cur_pic"]["tmp_name"],"sampleData/" . $_FILES["cur_pic"]["name"]);
        }
    }

   set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');

/** PHPExcel_IOFactory */
   include 'PHPExcel/IOFactory.php';
   $inputFileName = './sampleData/'.$_FILES["cur_pic"]["name"];
   echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory to  identify the format<br />';
   $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
   echo '<hr />';
   $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
   foreach($sheetData as $key => &$value) {
    if(is_array($value) && isset($value['A'])) $value = $value['A'];
   }
   $sql = mysql_query("SELECT email,type FROM subscribe WHERE status='0'");
   $ultimate_array = array();
   while($res = mysql_fetch_array($sql)){
     if($res['type'] == '1'){
      if (in_array($res['email'], $sheetData)) {
    unset($sheetData[array_search($res['email'], $sheetData)]);
      }
     }
   } 

   $replace_string2 = array_unique($sheetData);

   $today_date = date('Y-m-d h:i:s');

   foreach($replace_string2 as $ins_email){
    $chk_email = mysql_num_rows(mysql_query("SELECT id FROM add_email WHERE email='".$ins_email."'"));
    if($chk_email == 0){
        mysql_query("INSERT INTO add_email VALUES('','".$ins_email."','".$today_date."','1')");
    }
   }

   $final_email = array();
   foreach($replace_string2 as $f_email){
     $orig_sql = mysql_query("SELECT email,status FROM add_email WHERE email='".$f_email."'");
     while($res = mysql_fetch_array($orig_sql)){
        if($res['status'] == 1){
      array_push($final_email,$res['email']);       
        }
    else if($res['status'] == 0){
       $days = mysql_fetch_array(mysql_query("SELECT day FROM days"));
       $sql = mysql_query("SELECT email FROM add_email WHERE email='".$res['email']."' AND  DATEDIFF( NOW(),sending_date) > ".$days['day']);
       $no = mysql_num_rows($sql);
       if($no > 0){
        array_push($final_email,$f_email);  
           }    
         }
    }

     }

     $final_emails = array_unique($final_email);

     $_SESSION['record'] = $final_emails;

     foreach($final_emails as $ca){
    $ca_trim = trim($ca);
    mysql_query("UPDATE add_email SET sending_date='".$today_date."',status='0' WHERE email='".$ca_trim."'");
     }
            header('location:https://fgtpl.com/fugenx1/public_html/unsubscribe/Tests/14excel5.php');

}
4

2 回答 2

3

您可以检查php.ini文件中的 disable_functions 设置。如果这是共享主机

<?php echo phpinfo(); ?>检查设置。

如果共享主机是一个案例,我严重怀疑您是否可以上传 200MB。

于 2012-12-04T11:45:10.717 回答
0

如果你有你的专用服务器,你可以这样做:

  1. 登录到您的服务器
  2. 如果您在服务器上运行 whm+cpanel,请执行此操作

    tail -f /usr/local/apache/error.log 然后尝试上传。如果发生错误,您将在此处看到原因

  3. 如果您不使用 whm+cpanel,请执行此操作

    tail -f /var/log/apache/error.log 然后尝试上传。如果发生错误,您将在此处看到原因

在这两种情况下,您都需要找到您的 apache 错误文件。在此处粘贴 apache 日志文件的错误输出。

于 2012-12-04T12:09:31.673 回答