Page 1 of 1

insert csv.asp-file from external url into table

Posted: Thu Nov 24, 2011 1:44 am
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

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

Posted: Fri Nov 25, 2011 6:40 am
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

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

Posted: Fri Nov 25, 2011 8:29 am
by jolly123
Many thanks maxx99!!

That worked.
/jolly123