Jump to content

TXT from a webpage into a database


Dako

Recommended Posts

Hello people.

I have a problem and maybe you can help me =)

I have to put a txt file into a table from my database.

 

I can do it, if the file is in my computer.

 

$cfile = "D:\creleases.txt";
$sql = mysql_query ("LOAD DATA INFILE 'newreleases.txt' INTO TABLE table_comic FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n'" );

exit("done"); 

 

But if i try a txt file from a webpage, i can't do it.

For example: http://www.diamondcomics.com/shipping/newreleases.txt

 

How can i do it?

can you help me? please.

 

thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/174965-txt-from-a-webpage-into-a-database/
Share on other sites

like this you say?

 

$cfile = file_get_contents ('http://www.diamondcomics.com/shipping/newreleases.txt');
$txt = fwrite($cfile);
$sql = mysql_query ("LOAD DATA INFILE '$txt' INTO TABLE table_comic FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n'" );

:rtfm:fwrite()

 

Need to open the file (as this is a weekly release, make a blank text file on your server, fopen() that file, then fwrite() the $cfile) then sql the file you wrote to.

 

Next week, get new contents, open that file, write new data to it (as opposed to ammending), asql it again

 

week after etc..

sorry for not reading  =/

 

if i understand you correctly, this is what i have to do :

 

$cfile = file_get_contents ('http://www.diamondcomics.com/shipping/newreleases.txt', true);
$fp = fopen('creleases.txt', 'w');
fwrite ($fp, $cfile);
fclose ($fp);
$sql = mysql_query ("LOAD DATA INFILE '$fp' INTO TABLE table_comic FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n'" );

 

but it put nothing in the table.

i guess i'm doing something wrong.

 

 

i made something like this and it didn't work.  I don't know what is the problem here.

 

$file = file_get_contents ('http://www.diamondcomics.com/shipping/newreleases.txt', true);
$fp = fopen('creleases.txt', 'w');
fwrite ($fp, $file);
fclose($fp);
$cfile = "http://localhost/creleases.txt";

$sql = mysql_query ("LOAD DATA INFILE '$cfile' INTO TABLE table_comic FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n'" );

it put nothing in the table.

if i put this:

$file = file_get_contents ('http://www.diamondcomics.com/shipping/newreleases.txt', true);
$fp = fopen('creleases.txt', 'w');
fwrite ($fp, $file);
fclose($fp);
$cfile = 'http://localhost/creleases.txt';

$sql = mysql_query ("LOAD DATA INFILE '$cfile' INTO TABLE table_comic FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n'" )or die (mysql_error());

i get this : File 'http:\\localhost\creleases.txt' not found (Errcode: 22)

 

the file exists! i'm seeing it right now.

it works!!

thank you very much.

 

$file = file_get_contents ('http://www.diamondcomics.com/shipping/newreleases.txt', true);
$fp = fopen('D:\comicreleases.txt', 'w');
fwrite ($fp, $file);
fclose($fp);
$cfile = "D:\comicreleases.txt";

$sql = mysql_query ("LOAD DATA INFILE '$cfile' INTO TABLE table_comic FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n'" )or die (mysql_error());


$result = mysql_query("select * from table_comic WHERE precio = ''"); 
while($r=mysql_fetch_array($result)) 
{
$fecha = $r["fecha"];
$producto = $r["producto"];
$precio = $r["precio"];
$id = $r["id"];
$del = "DELETE FROM table_comic WHERE id=$id";
$delete = mysql_query($del);
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.