anon Posted December 26, 2007 Share Posted December 26, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/83277-help-defining-save_location/ Share on other sites More sharing options...
revraz Posted December 26, 2007 Share Posted December 26, 2007 $save_location = "myfile.txt"; //? Quote Link to comment https://forums.phpfreaks.com/topic/83277-help-defining-save_location/#findComment-423645 Share on other sites More sharing options...
Daleeburg Posted December 26, 2007 Share Posted December 26, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/83277-help-defining-save_location/#findComment-423649 Share on other sites More sharing options...
anon Posted December 26, 2007 Author Share Posted December 26, 2007 $save_location = "myfile.txt"; //? I want to save it to a database table. Quote Link to comment https://forums.phpfreaks.com/topic/83277-help-defining-save_location/#findComment-423668 Share on other sites More sharing options...
revraz Posted December 26, 2007 Share Posted December 26, 2007 Then you don't want put_file_contents, you want a INSERT sql query. Quote Link to comment https://forums.phpfreaks.com/topic/83277-help-defining-save_location/#findComment-423676 Share on other sites More sharing options...
anon Posted December 26, 2007 Author Share Posted December 26, 2007 So what would this look like. Where would i add it in the code? Quote Link to comment https://forums.phpfreaks.com/topic/83277-help-defining-save_location/#findComment-423677 Share on other sites More sharing options...
tinker Posted December 26, 2007 Share Posted December 26, 2007 Open the file, read contents (maybe encode if binary), then insert to db as normal. Quote Link to comment https://forums.phpfreaks.com/topic/83277-help-defining-save_location/#findComment-423685 Share on other sites More sharing options...
Daleeburg Posted December 26, 2007 Share Posted December 26, 2007 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)"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/83277-help-defining-save_location/#findComment-423691 Share on other sites More sharing options...
Daleeburg Posted December 26, 2007 Share Posted December 26, 2007 oh and make sure the data is good and sterilized before you put it in. Quote Link to comment https://forums.phpfreaks.com/topic/83277-help-defining-save_location/#findComment-423692 Share on other sites More sharing options...
anon Posted December 26, 2007 Author Share Posted December 26, 2007 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]); } Quote Link to comment https://forums.phpfreaks.com/topic/83277-help-defining-save_location/#findComment-423697 Share on other sites More sharing options...
revraz Posted December 26, 2007 Share Posted December 26, 2007 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]); } Quote Link to comment https://forums.phpfreaks.com/topic/83277-help-defining-save_location/#findComment-423699 Share on other sites More sharing options...
anon Posted December 26, 2007 Author Share Posted December 26, 2007 So if you were to look at my code, this is what it does: takes a url from the table "addurl" gets the content of the page (the HTML code) saves this HTML to a database. Quote Link to comment https://forums.phpfreaks.com/topic/83277-help-defining-save_location/#findComment-423712 Share on other sites More sharing options...
revraz Posted December 26, 2007 Share Posted December 26, 2007 Did you try Dale's code and see if it worked? Just replace your tablename and field name and give it a try. Quote Link to comment https://forums.phpfreaks.com/topic/83277-help-defining-save_location/#findComment-423715 Share on other sites More sharing options...
anon Posted December 26, 2007 Author Share Posted December 26, 2007 I want to run it as a daemon. Could i stop it when I' done? Quote Link to comment https://forums.phpfreaks.com/topic/83277-help-defining-save_location/#findComment-423720 Share on other sites More sharing options...
anon Posted December 26, 2007 Author Share Posted December 26, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/83277-help-defining-save_location/#findComment-423728 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.