Welcome Guest, Not a member yet? Register   Sign In
CSV upload, once uploaded to a temp folder overwrite the existing database
#57

[eluser]the_unforgiven[/eluser]
Right ok think i kinda got ya, before i do these error checking etc just wanted to show you what code i currently have:

Code:
$table = 'wc_program';
   $image_data = $this->upload->data();
      $fname = $image_data['file_name'];
      $fpath = $image_data['file_path'].$fname;
      $fh = fopen($fpath, "r+");
      $headers = 1;
  
   $insert_str = 'INSERT INTO wc_program (JobRef, Area, Parish, AbbrWorkType, WorkType, Timing, TrafficManagement, Location, Duration, Start, Finish) VALUES '."\n";

   if ($fh && $headers == 1) {
             // Create each set of values.
             while (($csv_row = fgetcsv($fh, 1000, ',')) !== false) {

                 foreach ($csv_row as &$row) {
                     $row = strtr($row, array("'" => "\\'", '"' => '\\"'));
                 }

                 $insert_str .= '("'
                     // Implode the array and fix pesky apostrophes.
                     .implode('","', $csv_row)
                     .'"),'."\n";
            
             }

             // Remove the trailing comma.
             $insert_str = rtrim($insert_str, ",\n");

             // Insert all of the values at once.
             $this->db->query($insert_str);
          
             $this->layout->buffer('content', 'program/success');
    $this->layout->render();
  
         }

So where would i put the strip headers thingy


Messages In This Thread
CSV upload, once uploaded to a temp folder overwrite the existing database - by El Forum - 04-08-2013, 06:29 AM



Theme © iAndrew 2016 - Forum software by © MyBB