Jump to content

How to write a file opened from fopen("URL")


galayman

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/95222-how-to-write-a-file-opened-from-fopenurl/
Share on other sites

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.

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.