Jump to content

Import csv file and upload it


mmj

Recommended Posts

I am trying to import csv file to wordpress using database.the files are uploaded in database but its not coming in wordpress .

The code is as below:

<?php

 

 

if(isset($_POST['submit']))

 

{

 

 

 

 

$fname=$_FILES["file"]["name"];

$datetime=$_FILES["file"][""];

 

  $chk_ext = explode(".",$fname);

if(strtolower(($chk_ext[1]) == "csv"))

 

        {

 

      $filename = $_FILES['file']['tmp_name'];

 

      $handle = fopen($filename, "r");

 

 

 

  while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)

 

        {

 

         

 

$fname=addslashes($data[0]);

 

$datetime=addslashes($data[1]);

 

$products=addslashes($data[2]);

 

$preset=addslashes($data[3]);

 

$format=addslashes($data[4]);

 

 

 

 

 

$sql = "INSERT into ".$wpdb->prefix ."facebook(filename,datetime,products,preset,format) values('$fname','$datetime','$products','$preset','$format')";

 

 

 

            mysql_query($sql) or die(mysql_error());

 

        }

 

   

 

        fclose($handle);

 

        echo "Successfully Imported";

 

    }

 

    else

 

    {

 

        echo "Invalid File";

 

    } 

 

}

?>

 

<form enctype="multipart/form-data" action="" method="post" name="uploadDetails">

<table cellpadding="4" cellspacing="0" border="1">

<tr>

<td><label for="upload_a_file">Upload File:</label></td>

<td><input type="file" name="file" id="upload_a_file" /></td>

</tr>

<tr>

 

</tr>

</table>

<input type="hidden" name="fd_upload" value="1" />

<input type="submit" value="Submit" class="allbutton" name="submit" />

</form>

Hope you will help me

   

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.