This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Mar 6th, 2011  |  syntax: PHP  |  size: 2.26 KB  |  views: 66  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?
  2. $type = $_POST['mimetype'];
  3. $xhr = $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
  4.                                                        
  5. if( !($_FILES['file']['error'] == 4) ) {                       
  6.  foreach($_FILES as $file) {
  7.   $n = $file['name'];
  8.   $s = $file['size'];
  9.  
  10.   $row = 0;
  11.  
  12.   ini_set('auto_detect_line_endings',TRUE);
  13.  
  14.   $filename = $file['tmp_name'];
  15.   $handle = fopen($filename, "r");
  16.   $contents = "<tbody>";
  17.   //$contents = "<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"css/emailList.css\" />\r\n<table cellspacing=\"0\" border=\"0\" align=\"left\" id=\"tblDisplay\" cellpading=\"0\" class=\"tblDisplayEmail\" style=\"font-family: verdana; font-size: 10px; width:485px;\">\r\n";
  18.  
  19.   while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
  20.    if ($row == 0) {
  21.     // this is the first line of the csv file
  22.     // it usually contains titles of columns
  23.     $num = count($data);
  24.     $row++;
  25.     //$contents = $contents . "<thead>\r\n<tr id=\"chkrow\" class=\"trBorder\">\r\n" . "<th><input type=\"checkbox\" id=\"checkall\" /></th> <th>&nbsp;</th> <th style=\"text-align: left;\">name</th> <th style=\"text-align: left;\">email</th>\r\n" . "</tr>\r\n</thead>\r\n<tbody id=\"tblDisplayBody\">\r\n";
  26.    }
  27.    else {
  28.     // this handles the rest of the lines of the csv file
  29.     $num = count($data);
  30.     $row++;
  31.     if( filter_var($data[1], FILTER_VALIDATE_EMAIL) != false ) {
  32.      if(strlen($data[0]) == 0) {
  33.       $data[0] = "No Name";
  34.      }
  35.      if(strlen($data[0]) > 31) {
  36.       $data[0] = substr($data[0], 0, 30) . ".";
  37.      }
  38.      
  39.      $contents = $contents . "<tr class=\"trBorderLight\">\r\n<td style=\"text-align: center;\"><input type=\"checkbox\" value=\"$row\" name=\"cvsEmail\" /></td> <td>&nbsp;</td> <td style=\"text-align: left;\">$data[0]</td> <td style=\"text-align: left;\">$data[1]</td>\r\n</tr>\r\n";
  40.     }
  41.    } // end ELSE
  42.   } // end WHILE
  43.  
  44.   //$contents = $contents . "</tbody>\r\n</table>\r\n";
  45.   $contents = $contents . "</tbody>\r\n";
  46.   fclose($handle);
  47.   ini_set('auto_detect_line_endings',FALSE);
  48.  
  49.   // Echo the files contents
  50.   echo $contents;
  51.  
  52.   if (!$n) continue;
  53.   //echo "File: $n ($s bytes)";
  54.  } // end FOREACH
  55. } // end if( !($_FILES['file']['error'] == 4) )
  56. else { var_dump($_POST); echo "<br><hr>"; var_dump($_FILES); }         
  57. ?>
clone this paste RAW Paste Data