Jump to content

Help defining save_location!


anon

Recommended Posts

Hi, my code looks like this

<?php
$dbhost = '*****';
$dbuser = '*****';
$dbpass = '*****';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error with database');

$dbname = 'url';
mysql_select_db($dbname);

$getlist=mysql_query("SELECT u_id FROM addurl");

while($row=mysql_fetch_array($getlist)){
   $text = file_get_contents($row[0]);
   file_put_contents($save_location, $row[0]);
}
?>

 

As you can see, i need to define $save_location. Thing is, how would i give the code a place to save to?

Link to comment
https://forums.phpfreaks.com/topic/83277-help-defining-save_location/
Share on other sites

After a quick look at the Man page.

 

http://us2.php.net/file_put_contents

 

I would guess that you can put any url or folder direction in there, so just put in the direction from the file to where you want it to go.  You have to remember where the file is running from though.

 

So if it runs from a the root directory then "/foo/bar.txt"

 

If it runs from a level up from the root then "./foo/bar.txt"

 

Or if you want to base the file off the root directory "../foo/bar.txt"

 

(I may have my .. and . mixed up, I tend to always do that.)

 

~D

Then you don't want put_file_contents, you want a INSERT sql query.

 

<?php
$dbhost = '*****';
$dbuser = '*****';
$dbpass = '*****';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error with database');

$dbname = 'url';
mysql_select_db($dbname);

$getlist=mysql_query("SELECT u_id FROM addurl");

while($row=mysql_fetch_array($getlist)){
   $text = file_get_contents($row[0]);
   mysql_query("insert into TableName (TableColoum) values ($text)");
}
?>

Would this also work?

<?php
$dbhost = '*****';
$dbuser = '*****';
$dbpass = '*****';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error with database');

$dbname = 'url';
mysql_select_db($dbname);

$getlist=mysql_query("SELECT u_id FROM addurl");
$save_location=mysql_query("INSERT INTO addurl");

while($row=mysql_fetch_array($getlist)){
   $text = file_get_contents($row[0]);
   file_put_contents($save_location, $row[0]);
}

No, you don't want to use a put_file command, you want to use a SQL command.

 

Would this also work?

<?php
$dbhost = '*****';
$dbuser = '*****';
$dbpass = '*****';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error with database');

$dbname = 'url';
mysql_select_db($dbname);

$getlist=mysql_query("SELECT u_id FROM addurl");
$save_location=mysql_query("INSERT INTO addurl");

while($row=mysql_fetch_array($getlist)){
   $text = file_get_contents($row[0]);
   file_put_contents($save_location, $row[0]);
}

Did you try Dale's code and see if it worked?  Just replace your tablename and field name and give it a try.

 

The cron daemon gave me this error:

 

Warning:  mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/****/public_html/****/******.php on line 13

 

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.