View Full Version : stupid php question (stream_get_contents)
cursed
06-26-2007, 09:02 PM
I can't seem to get this php code to work:
<?php
$file = '/home/gamesjet/public_html/test.txt';
if (is_writable($file) == false) {
die('Unable to write to file');
}
// The data
$data = fopen("http://www.example.com/", "a+");
// Write to file
file_put_contents ($file, $data);
?>
i get this error:
Unable to write to file
test.txt is chmodded to 777.
That's probably because you're trying to write the file handler to the file. You need to read the data from it and write that instead.
cursed
06-26-2007, 10:16 PM
thanks for the reply. glad you got promoted to Global Moderator :) .
i changed my code a bit, and i can echo it, but i cant record it into a file. i think im missing something very obvious.
<?php
$file = fopen("/home/gamesjet/public_html/test.txt", "a+");
if ($stream = fopen('http://www.example.net', 'r')) {
// print the first 5 bytes
$contents = stream_get_contents($stream, 100000);
echo $contents;
echo file_put_contents($file, $contents);
fclose($stream);
}
?>
thetestingsite
06-26-2007, 11:33 PM
Try taking out the echo before file_put_contents().
<?php
$file = fopen("/home/gamesjet/public_html/test.txt", "a+");
if ($stream = fopen('http://www.example.net', 'r')) {
// print the first 5 bytes
$contents = stream_get_contents($stream, 100000);
echo $contents;
echo file_put_contents($file, $contents);
fclose($stream);
}
?>
That should get it to work (or at least produce an error if none is present now).
Hope this helps.
cursed
06-27-2007, 03:42 AM
error:
Warning: fopen(/home/gamesjet/public_html/test.txt) [function.fopen]: failed to open stream: Permission denied in /home/gamesjet/public_html/proxy/index.php on line 3
You have reached this web page by typing "example.com", "example.net", or "example.org" into your web browser.
These domain names are reserved for use in documentation and are not available for registration. See RFC 2606, Section 3.
tech_support
06-27-2007, 06:34 AM
Try chmod the directory.
thetestingsite
06-27-2007, 04:07 PM
You don't want to do that in this case, because the file is located in the OP's root directory. You may want to make sure that the file exists and is writeable, other than that I have no clue.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.