Solved

CSV Import to MySQL through PHP

Posted on 2009-07-01
6
302 Views
Last Modified: 2013-12-13
I love PHPMyAdmin, but I want something a little more "secure" that I can setup for an average user.  Even something that will import a file from the same location over and over by pressing a button.

The file is CSV file with one strange twist.  One field has several filenames separated by | though like I said, it is a single field called attachments.

Anyone know of any software or good script to modify that could provide this functionality?
0
Comment
Question by:hydrazi
6 Comments
 
LVL 14

Expert Comment

by:shobinsun
ID: 24754360
0
 
LVL 5

Expert Comment

by:kingofnines
ID: 24754383
it is a fairly easy proccess to parse a CSV file into its seperate fields and then upload them to a table. Take a look at the explode() function...

http://us3.php.net/manual/en/function.explode.php

Using explode() you can  parse your CSV record into an array. Then traverse the array in a loop and build your upload statement. Post a sample of your file and I will write a quick example script.


Alan
0
 
LVL 5

Expert Comment

by:kingofnines
ID: 24754443
The second article shobinsun gave you is an example of what I was saying. I didn't see he had posted before I posted.


Alan
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 24754915
PHP has a built-in function that may be helpful:
http://nl3.php.net/manual/en/function.fgetcsv.php

You can isolate the filenames that are "pipe-delimited" and get an array with this sort of thing.  The trim() is there in case you get stray whitespace.
http://nl3.php.net/manual/en/function.explode.php

HTH, ~Ray
<?php

$attch = 'file.one|file.two | file.tre| file.for';

$array = explode('|', $attch);

foreach ($array as $pointer => $thing) { $array[$pointer] = trim($thing); }

var_dump($array);

Open in new window

0
 

Author Closing Comment

by:hydrazi
ID: 31598770
Awesome!  Thank you
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 24814211
Thanks for the points!  It's a good question. ~Ray
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now