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
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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

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.