Solved

CSV Import to MySQL through PHP

Posted on 2009-07-01
6
304 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 109

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 109

Expert Comment

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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

838 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