pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

jawaad private pastebin - collaborative debugging tool What's a private pastebin?


Posted by Jawaad on Thu 21 Aug 17:46
report abuse | download | new post

  1. <?php
  2. // UPLOAD CSV CUSTOM
  3. // Ver. 1.0
  4. // by Jawaad
  5. // zaibatsu@gmail.com
  6.  
  7. if(!defined('jin')) { die('nice try..'); }
  8.  
  9. if($_POST[upload_csv]=="1") {
  10.         $table_name="`".$_POST[table_name]."`";
  11.         if(!$_FILES["file_csv"]["name"]) {
  12.                 echo "<script>alert('Please Browse File.. CSV.');</script>";
  13.         } else if(substr($_FILES["file_csv"]["name"], -3) != "csv") {
  14.                 echo "<script>alert('File ".substr($_FILES["file_csv"]["name"],-3)." not support. Please use CSV extension');</script>";
  15.         } else if($_FILES["file_csv"]["size"]>=1672864) {
  16.                 echo "<script>alert('File size is too big. File max 1.5 MB');</script>";
  17.         } else {
  18.                 // READ FIELD FROM TABEL
  19.                 $sql_tabel = mysql_query("SELECT * FROM ".$table_name."");
  20.                 $numfields = mysql_num_fields($sql_tabel);
  21.                 $field_name = "";
  22.                 for ($i=0; $i < $numfields; $i++) {
  23.                         $get_field = mysql_field_name($sql_tabel, $i);
  24.                         if($i == 1) {
  25.                                 $field_name .= "`".$get_field."`";
  26.                         } elseif($i > 1) {
  27.                                 $field_name .= ", `".$get_field."`";
  28.                         }
  29.                 }
  30.                 copy($_FILES["file_csv"]["tmp_name"], "tmp/".$_FILES["file_csv"]["name"]);
  31.                 $ifile = fopen("tmp/".$_FILES["file_csv"]["name"],"r");
  32.                 $no=1;
  33.                 $jum_value = $numfields - 1;
  34.                 while (($file_list = fgetcsv($ifile, 1000, ",")) !== FALSE) {
  35.                         if($no > 1) {
  36.                                 $field_value = "";
  37.                                 for ($i=0; $i < $jum_value; $i++) {
  38.                                                 if($i == 0) {
  39.                                                         $field_value .= "'".$file_list[$i]."'";
  40.                                                 } else {
  41.                                                         $field_value .= ", '".$file_list[$i]."'";
  42.                                                 }
  43.                                 }
  44.                                         $sql = "INSERT INTO ".$table_name." (".$field_name.") VALUES (".$field_value.")";
  45.                                         /*
  46.                                         echo "<pre>";
  47.                                         echo $sql;
  48.                                         echo "</pre>";
  49.                                         */
  50.                                         $ex = mysql_query($sql) OR die ("<br>ERROR, DATA TIDAK BISA MASUK...<br>");
  51.                                         if(!$ex) {
  52.                                                 echo "<script>alert(\"Sorry, Error....\");location.href='?do=upload_csv';</script>";
  53.                                         } else {
  54.                                                 echo "<script>alert(\"Succesed.\");location.href='?do=upload_csv';</script>";
  55.                                         }
  56.                         }
  57.                         $no++;
  58.                 }
  59.                 fclose($ifile);
  60.                 unlink("tmp/".$_FILES["file_csv"]["name"]) OR die ("Cannot DEL file tmp/".$_FILES["file_csv"]["name"]);
  61.         }
  62. }
  63. ?>
  64.  
  65. <form method="post" enctype="multipart/form-data">
  66. <br><br>
  67. <h2>Upload CSV</h2>
  68. <table border="0" cellspacing="0" cellpadding="3">
  69. <tr>
  70.         <td valign="top">Table Name</td><td valign="top">: <input name="table_name"></td>
  71. </tr>
  72. <tr>
  73.         <td valign="top">File CSV</td><td valign="top">: <input type="file" name="file_csv" value="1"></td>
  74. </tr>
  75. <tr>
  76.         <td valign="top" colspan="2">
  77.                 <input type="hidden" name="upload_csv" value="1">
  78.                 <input type="submit" name="submit" value="UPLOAD .CSV">
  79.         </td>
  80. </tr>
  81. </table>
  82. </form>
  83.  
  84.  
  85. <?php
  86.  
  87. ?>

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post