Could someone help me with this problem: have a bot on shell on one server, which make log file (log.txt) and I want to open that file on a specific page on my site which is on other server. I've tried to use following command (fopen) in .php file: <?php $file = fopen('http://shell-sample.com/user/archiva/log.txt', 'r') or exit("Unable to open file!"); while(!feof($file)) { echo fgets($file). "<br />"; } fclose($file); ?> but I always get message: Warning: fopen(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/user/public_html/index.php on line 2 Warning: fopen(http://shell-sample.com/user/archiva/url.txt): failed to open stream: Success in /home/user/public_html/index.php on line 2 Unable to open file! Don't know what is the problem, is that right command and is it written right? or is there any other way (command) I could do same - open that file.
Who is your host? I tried to use fopen on dreamhost and they do not allow it, so I had to switch it to curl and it worked perfect.
Your host may have disabled 'allow_url_fopen' . Try using cURL instead to access remote files. http://www.php.net/curl Thomas
I've tried curl and got this message: Warning: fopen(url.txt): failed to open stream: Permission denied in /home/user/public_html/qqq/q.php on line 4 Warning: curl_setopt(): supplied argument is not a valid File-Handle resource in /home/user/public_html/qqq/q.php on line 6 Warning: fclose(): supplied argument is not a valid stream resource in /home/user/public_html/qqq/q.php on line 11 what's now wrong?
Are you sure you are using curl in the correct way? I will give you an example code: $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,"http://shell-sample.com/user/archiva/log.txt"); curl_setopt($ch,CURLOPT_HEADER,0); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); $output = curl_exec($ch); curl_close($ch); PHP: After that code, $output should contain the contents of the file if not error occured. Thomas
the file you are trying to open via fopen does not exist. fopen cannot open the url http://shell-sample.com/user/archiva/log.txt, hence the error: php_network_getaddresses: getaddrinfo failed: check if the file exists by trying to open it in the browser
daniah, url "http://shell-sample.com/user/archiva/log.txt" you tried to follow is just a example, real url is http://shells.hostingmania.co.yu/~skanner/arhiva/log.txt coderlinks, when I use code you suggested no errors occured but also doesn't show me contents of file.... could u please use http://shells.hostingmania.co.yu/~skanner/arhiva/log.txt url and figure out what's wrong. Thanx in advance. Sorry on all trouble, I'm just a confused begginer.
My code only fetches the contents of the file into the variable $output. Then you have to 'echo' it. echo $output; PHP: Or you can directly put the contents from cURL to the browser, just use this modified code $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,"http://shell-sample.com/user/archiva/log.txt"); curl_setopt($ch,CURLOPT_HEADER,0); curl_exec($ch); if(curl_errno($ch)) { echo curl_error($ch); } curl_close($ch); PHP: This one also checks for errors and displays them. Thomas
try this code: $URL="http://shell-sample.com/user/archiva/log.txt"; $file = fopen("$URL", "r"); $r = ""; do { $data = fread($file, 8192); if (strlen($data) == 0) { break; } $r .= $data; } while (true); fclose ($file); echo $r;
It would be better if you could put this code in a PHP file <?php phpinfo(); ?> PHP: And give me the URL to that file. That would give some info as to whats wrong. Thomas
With my host I had to curl any files/urls that are on a different server and write them to a text file on my server and fopen that. They won't let you do a whole lot with files that aren't yours.
DANIAH, KISS! FINALLY! thank you so much, that code finally works! sorry again for all trouble... btw, when I tried it first time, I typed one letter wrong my mistake
gald it finally worked...next time you get an Warning: fopen(): php_network_getaddresses: getaddrinfo failed: error, you know what to do