GOOGLE

aku nok ndi : /home/astwardha/public_html/polylibrary/csv/
File Up :
aku nok ndi : /home/astwardha/public_html/polylibrary/csv/ajaxData.php

<?php
//load the database configuration file
include 'dbcon.php';
date_default_timezone_set('Asia/Kolkata');
if(isset($_POST['importSubmit'])){
    
    //validate whether uploaded file is a csv file
    $csvMimes = array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel', 'text/plain');
    if(!empty($_FILES['file']['name']) && in_array($_FILES['file']['type'],$csvMimes)){
        if(is_uploaded_file($_FILES['file']['tmp_name'])){
            
            //open uploaded csv file with read only mode
            $csvFile = fopen($_FILES['file']['tmp_name'], 'r');
            
            //skip first line
            fgetcsv($csvFile);
            
            //parse data from csv file line by line
            while(($line = fgetcsv($csvFile)) !== FALSE){
                
                    //insert member data into database
                   mysql_query("INSERT INTO `book` (`date_added`,`acc_no`,`author`,`book_title`, `publisher_name`,`publication_date`,`subject`,`book_type`,`date_time`) VALUES ('".addslashes($line[0])."','".addslashes($line[1])."','".addslashes($line[2])."','".addslashes($line[3])."','".addslashes($line[4])."','".addslashes($line[5])."','".addslashes($line[6])."','".addslashes($line[7])."','".date("Y-m-d")."')");

                
            }
            
            //close opened csv file
            fclose($csvFile);

            $qstring = '?status=succ';
        }else{
            $qstring = '?status=err';
        }
    }else{
        $qstring = '?status=invalid_file';
    }
}

//redirect to the listing page
header("Location: index.php".$qstring);

Copyright © 1945 - 2024 GOOGLE