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
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'" );

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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