Posted by Jawaad on Thu 21 Aug 17:46
report abuse | download | new post
- <?php
- // UPLOAD CSV CUSTOM
- // Ver. 1.0
- // by Jawaad
- // zaibatsu@gmail.com
- if($_POST[upload_csv]=="1") {
- $table_name="`".$_POST[table_name]."`";
- if(!$_FILES["file_csv"]["name"]) {
- echo "<script>alert('Please Browse File.. CSV.');</script>";
- } else if($_FILES["file_csv"]["size"]>=1672864) {
- echo "<script>alert('File size is too big. File max 1.5 MB');</script>";
- } else {
- // READ FIELD FROM TABEL
- $field_name = "";
- for ($i=0; $i < $numfields; $i++) {
- if($i == 1) {
- $field_name .= "`".$get_field."`";
- } elseif($i > 1) {
- $field_name .= ", `".$get_field."`";
- }
- }
- $no=1;
- $jum_value = $numfields - 1;
- if($no > 1) {
- $field_value = "";
- for ($i=0; $i < $jum_value; $i++) {
- if($i == 0) {
- $field_value .= "'".$file_list[$i]."'";
- } else {
- $field_value .= ", '".$file_list[$i]."'";
- }
- }
- $sql = "INSERT INTO ".$table_name." (".$field_name.") VALUES (".$field_value.")";
- /*
- echo "<pre>";
- echo $sql;
- echo "</pre>";
- */
- if(!$ex) {
- echo "<script>alert(\"Sorry, Error....\");location.href='?do=upload_csv';</script>";
- } else {
- echo "<script>alert(\"Succesed.\");location.href='?do=upload_csv';</script>";
- }
- }
- $no++;
- }
- }
- }
- ?>
- <form method="post" enctype="multipart/form-data">
- <br><br>
- <h2>Upload CSV</h2>
- <table border="0" cellspacing="0" cellpadding="3">
- <tr>
- <td valign="top">Table Name</td><td valign="top">: <input name="table_name"></td>
- </tr>
- <tr>
- <td valign="top">File CSV</td><td valign="top">: <input type="file" name="file_csv" value="1"></td>
- </tr>
- <tr>
- <td valign="top" colspan="2">
- <input type="hidden" name="upload_csv" value="1">
- <input type="submit" name="submit" value="UPLOAD .CSV">
- </td>
- </tr>
- </table>
- </form>
- <?php
- ?>
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.