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');
}