MiX1.TK
Site menu
Login form
Section categories
Web Development [20]
Learn about PHP & Web Development
Education [4]
Learn for Free
Knowledge & Tricks [0]
General Knowledge,computer Knowledge & tricks
Writing World [2]
A MiX World of SmS on Various Topics
Search
Main » 2012 » November » 6 » Read Csv Files without using any external class
10:21 PM
Read Csv Files without using any external class
how to read Csv  Files in php without using any external class

 <?php
if($_REQUEST)
{
  $filePath="./uploads/". $_FILES["userfile"]["name"];
  move_uploaded_file($_FILES["file"]["tmp_name"] ,$filePath);
  $sql = array();
   if (($handle = fopen($filePath, "r")) !== FALSE)
    {
          $i=1;
           while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
           {
 //all the column data will come of a subsequent row will cone in data array
                if($i==1)
                {
                   $i++;
                   continue;
                                   
                 }
                  else
                  {
                      $sql[] = '("'.$data[1].'","'.$data[2].'","'.$data[3].'","'.$data[4].'")';
                   }
            }

        fclose($handle);
                           
       }   
                       
                        // make a sql query  to execute..
                        $data_query='INSERT INTO health_care_standard_uploads(name,age,address,sex) VALUES '.implode(',', $sql);
                       
  $res=mysql_query($data_query);
     if($res)      
    {           
        echo '<script>alert("succesfully imported !");</script>';
    }
                                        
   
 }
?>
Category: Web Development | Views: 178 | Added by: admin-priyank | Rating: 5.0/1
Total comments: 0
Name *:
Email *:
Code *:
Calendar
«  November 2012  »
SuMoTuWeThFrSa
    123
45678910
11121314151617
18192021222324
252627282930
Entries archive
Our poll
Rate my site
Total of answers: 4
Site friends
  • Create a free website
  • Online Desktop
  • Free Online Games
  • Video Tutorials
  • All HTML Tags
  • Browser Kits
  • Statistics

    Total online: 1
    Guests: 1
    Users: 0
    Creative Commons License
    Free Downloads and Services by MiX1 is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License
    Copyright MyCorp © 2018