insert csv.asp-file from external url into table

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
jolly123
Forum Newbie
Posts: 2
Joined: Thu Nov 24, 2011 1:28 am

insert csv.asp-file from external url into table

Post by jolly123 »

Hi,
Im a newbie to this forum (and php ;-) ) so be gentle... :-) Hopyfully someone can bring light to a php/mysql-question thats been bothering me for weeks.

Im trying to make my php-script read an external file from a url (www.somesite.com/file.asp) which holds csv-values and update an existing mysql-table with the file. As you can see, the external file is saved as an .asp-file.

While browsing the web there seems to be many functions that should be able to fullfill my task (fopen, str_getcsv, fread, file_get_contents). I guess there are many pros and cons using the different functions? So which one would you use and how would you solve the problem?

Reading the csv line by line? Read the entire file into an array or string? Security issues?

Many thanks in advance!!
/Jolly123
maxx99
Forum Contributor
Posts: 142
Joined: Mon Nov 21, 2011 3:40 am

Re: insert csv.asp-file from external url into table

Post by maxx99 »

You could read remote file with http://www.php.net/manual/en/function.f ... ntents.php

Code: Select all

<?php
$csv = file_get_contents('www.somesite.com/file.asp');
echo $csv;
?>
Create temp file with $csv content (thats entire file) fopen(), fwrite()/fputs(), fclose()
Read this file (line by line) with http://www.php.net/manual/en/function.fgetcsv.php
jolly123
Forum Newbie
Posts: 2
Joined: Thu Nov 24, 2011 1:28 am

Re: insert csv.asp-file from external url into table

Post by jolly123 »

Many thanks maxx99!!

That worked.
/jolly123
Post Reply