galayman Posted March 9, 2008 Share Posted March 9, 2008 Hi guys I have this code <? // the site we want to read $host = "www.some-site.com"; // the file we want to read $file = "some-file.htm"; // construct a header for our request $hdrs = array( 'http' => array( 'method' => "POST", 'header'=> "accept-language: en\r\n" . "Host: $host\r\n" . "Referer: http://$host\r\n" ) ); $context = stream_context_create($hdrs); $fp = fopen("http://" . $host . "/" . $file, 'r', false, $context); // $contents = Here I don't know how to read inside $fp ------- Missing code ------- $file = fopen("/home/user/my_file", "w+"); fwrite ($file, $contents); fclose($file); fclose($fp); ?> This code is to read file from somesite, the page is protected using referrer, everyday i open the site using browser, but i need to read it quickly, thats why i use that script. I need to write the content to my_file located at /home/user/ The question is, how to read $fp in string ? In the end it will writed to my_file Please help, I already using fgets, fread, file_get_contents. I'm new to php, that's why i cannot solve this problem. Thank You. Quote Link to comment https://forums.phpfreaks.com/topic/95222-how-to-write-a-file-opened-from-fopenurl/ Share on other sites More sharing options...
Daniel0 Posted March 9, 2008 Share Posted March 9, 2008 $contents = fread($fp); Quote Link to comment https://forums.phpfreaks.com/topic/95222-how-to-write-a-file-opened-from-fopenurl/#findComment-487743 Share on other sites More sharing options...
galayman Posted March 9, 2008 Author Share Posted March 9, 2008 No thats not working, I've tried that before fread() need the filesize and i cannot get it. this is the warning : Warning: Wrong parameter count for fread() in /var/www/html/test.php on line 22 Quote Link to comment https://forums.phpfreaks.com/topic/95222-how-to-write-a-file-opened-from-fopenurl/#findComment-488079 Share on other sites More sharing options...
BlueSkyIS Posted March 9, 2008 Share Posted March 9, 2008 the page is protected using referrer, everyday i open the site using browser, but i need to read it quickly, thats why i use that script. Quote Link to comment https://forums.phpfreaks.com/topic/95222-how-to-write-a-file-opened-from-fopenurl/#findComment-488080 Share on other sites More sharing options...
galayman Posted March 9, 2008 Author Share Posted March 9, 2008 Whats wrong??? It's useless anyway to protect it, because, if we can read it, we can get the contents, i'm not trying to attack it, i just need the contents. I read a lot of web everyday, i want to make my own single page, and inside it will display all the info that i've saved before using this method. Quote Link to comment https://forums.phpfreaks.com/topic/95222-how-to-write-a-file-opened-from-fopenurl/#findComment-488086 Share on other sites More sharing options...
galayman Posted March 9, 2008 Author Share Posted March 9, 2008 I'm offended, blame me for being dumb at PHP and asking question. Quote Link to comment https://forums.phpfreaks.com/topic/95222-how-to-write-a-file-opened-from-fopenurl/#findComment-488091 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.