vladkras

CSV upload

Sep 11th, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.84 KB | None | 0 0
  1. $file_name = "photo_export_file.v3.csv";
  2. if (($handle = fopen($file_name, "r")) !== FALSE) {
  3.     while (($data = fgetcsv($handle, 100, ";")) !== FALSE) {
  4.  
  5.  
  6.         $values = "('".$data[2]."', '".$data[3]."', '".$data[4]."', ";
  7.  
  8.         $pic_path = substr($data[1], 1);
  9.         $pic_name = array_pop(explode("/", $data[1]));
  10.         $pic_name = strtolower($pic_name);
  11.  
  12.         $values .= "'".$pic_name.":image/jpeg:".filesize($pic_path).":".$data[2]."/".$data[3]."/".$pic_name."', ";
  13.  
  14.         $thumb_path = substr($data[0], 1);
  15.         $thumb_name = array_pop(explode("/", $data[0]));
  16.         $thumb_name = strtolower($thumb_name);
  17.  
  18.         $values .= "'".$thumb_name.":image/jpeg:".filesize($thumb_path).":".$data[2]."/".$data[3]."/".$thumb_name."')";
  19.        
  20.        
  21.  
  22.         $que = "INSERT INTO Message2005 (Subdivision_ID, Sub_Class_ID, AlbumID, Picture, Preview) VALUES ".$values;
  23. #        if (!file_exists($pic_path) or !file_exists($thumb_path)) {
  24. #           echo "no ".$pic_path."or no ".$thumb_path."\n";
  25. #        }
  26. #        else {
  27.             if (!file_exists("netcat_files/".$data[2]."/".$data[3])) {
  28.                 //mkdir("netcat_files/".$data[2]) or die("could not create dir netcat_files/".$data[2]);
  29.                 mkdir("netcat_files/".$data[2]."/".$data[3], 0777, true) or die("could not create dir netcat_files/".$data[2]."/".$data[3]);
  30.             }
  31.             rename($pic_path, "netcat_files/".$data[2]."/".$data[3]."/".$pic_name) or die("could not move ".$pic_path."to netcat_files/".$data[2]."/".$data[3]."/".$pic_name);
  32.             rename($thumb_path, "netcat_files/".$data[2]."/".$data[3]."/".$thumb_name) or die("could not move ".$thumb_path);
  33.             mysql_query($que) or die(mysql_error());
  34.             echo mysql_insert_id()." successful\n";
  35.             //echo $que."\n";
  36. #        }
  37.    }
  38.     fclose($handle);
  39. }
  40. else echo "could not open file";
Advertisement
Add Comment
Please, Sign In to add comment