I have the below code that tries to pull text from an url.
include_once("html_parser/simple_html_dom.php");
$html=file_get_html("http://82.77.18.164:8080/Iphone/get_puncte.php");
print_r($html);
echo file_get_contents("http://82.77.18.164:8080/Iphone/get_puncte.php");
echo stream_get_contents(fopen('http://82.77.18.164:8080/Iphone/get_puncte.php', "r"));
If i access the url in my browser it works fine, but in when i access the php file with the code above i receive the below erros.
PHP Warning: file_get_contents(http://82.77.18.164:8080/Iphone/get_puncte.php): failed to open stream: Connection refused
PHP Warning: stream_get_contents() expects parameter 1 to be resource, boolean given in /home/xxxxx/public_html/test.php on line 9
Any idea ?
Some servers deny using an IP address instead would recommend to use curl
Related
I am trying to use some of the scripts on this site
http://www.tubekit.org/tools.php
As you can see under the Usage section it gives you some arguments to put into the command line
php extractYTVideoURLs.php yturls.txt mylist.txt
I have downloaded the extract php file and made the 2 text files yet I only get this answer in the command line.
c:\php>php C:/Users/extractYTVideoURLs.php yturls.txt my
list.txt
Warning: fopen(yturls.txt): failed to open stream: No such file or directory in
C:\Users\extractYTVideoURLs.php on line 21
Warning: fgets() expects parameter 1 to be resource, boolean given in C:\Users\extractYTVideoURLs.php on line 24
Warning: fclose() expects parameter 1 to be resource, boolean given in C:\Users\
extractYTVideoURLs.php on line 52
The error seems pretty clear. On line 21 of C:\Users\extractYTVideoURLs.php the code calls fopen() on a file called yturls.txt which it can't find. Where is this file? Does it exist at all?
It's generally best practice to reference a file with a fully-qualified path name. Note that you're currently in the directory c:\php so if that file isn't in the current working directory then just referencing it by name isn't going to find it. You'll need to reference the file by where it's located. Potentially something like this:
php C:/Users/extractYTVideoURLs.php C:/Path/to/yturls.txt C:/Path/to/mylist.txt
I'm trying to write in a txt file the data i get from a html form, but I get this error: Warning: fopen(/var/www/4/datos.txt): failed to open stream: Permission denied in /var/www/4/ComprobacionFormulario.php on line 13 Warning: fwrite() expects parameter 1 to be resource, boolean given in /var/www/4/ComprobacionFormulario.php on line 16 Warning: fclose() expects parameter 1 to be resource, boolean given in /var/www/4/ComprobacionFormulario.php on line 17
'datos.txt' Is the file where i'm trying to write. Here is my php code:
error_reporting(E_ALL);
ini_set('display_errors', true);
$des=$_POST['description'];
$cant=$_POST['quantity'];
$prec=$_POST['price'];
$nombrearchivo="datos.txt";
$content="Description: $des\tQuantity: $cant\tPrice: $prec\n";
$handle=fopen($nombrearchivo, 'w');
fwrite($handle, $content);
fclose($handle);
From the manual: [fopen] Returns a file pointer resource on success, or FALSE on error.
Looks like your fopen call is failing. Try using an absolute URL to your text file. Make sure your folder is CHMODded correctly and the file also (777 permissions)
I have following code:
$fh=fopen($api,"r");
$theData = fgets($fh);
echo $theData;
This throws the error as :
Warning: fopen(http://xxxxxx.xxxxxxxx.com:8080) [function.fopen]: failed to open stream: Connection refused in /home/xxxx/public_html/xxxx/index.php on line 18
Warning: fgets(): supplied argument is not a valid stream resource in /home/xxxx/public_html/xxxx/index.php on line 19
What is the solution for this?
Your file did not open as you intended. Check the value of $api and be sure the file name is in the current working directory, or the entire path to the file.
Since it is a remote system on :8080, be sure the port is open to the public. This is typically a value reserved for localhost (ie: the webserver is only a webserver to that computer, no one else's) and wouldn't be accessible to you. If the url you are opening is the same computer you are using, navigate to the file using local folders instead.
I had a website that pulled videos from a user's account using a public XML feed. The feed's URL is:
https://gdata.youtube.com/feeds/api/users/USERNAME/uploads
Where USERNAME is dynamically assigned via a PHP variable. The code to hit this URL and grab the contents is:
$file = file_get_contents('https://gdata.youtube.com/feeds/api/users/'.$channel.'/uploads');
$xml = simplexml_load_file($file);
However, this is now throwing a weird error:
Warning: file_get_contents() [function.file-get-contents]: Couldn't
resolve host name in /home/dpw/public_html/inc/modules/youtube.php on
line 46
Warning:
file_get_contents(https://gdata.youtube.com/feeds/api/users/dpwrestling/uploads)
[function.file-get-contents]: failed to open stream: operation failed
in /home/dpw/public_html/inc/modules/youtube.php on line 46
Warning: simplexml_load_file() [function.simplexml-load-file]: I/O
warning : failed to load external entity "" in
/home/dpw/public_html/inc/modules/youtube.php on line 47
Warning: Invalid argument supplied for foreach() in
/home/dpw/public_html/inc/modules/youtube.php on line 49
I'm not sure what the problem is, as visiting the URL in my web browser returns the XML fine. Why is my PHP script now having trouble retrieving it?
For the record, the allow_url_fopen is still enabled in my hosting environment as I checked using echo ini_get('allow_url_fopen'), which printed 1.
I am trying to get some profile information in my Facebook via PHP as specified in,
http://developers.facebook.com/docs/authentication/
$user = json_decode(file_get_contents(
'https://graph.facebook.com/me?access_token=' .
$cookie['access_token']))->me;
When I run this code, I am getting the following warning:
Warning: file_get_contents(.....) [function.file-get-contents]: failed to open stream: No such file or directory in /home/website/public_html/helloworldpp/index.php on line 30
I have truncated and add "....." instead of the actual URL. However, when I access the "....." url via the browser I am getting the json response. I am not sure why I am unable to get it via the php code. Could some one please help me out?
Thanks a bunch.
It's possible that opening websites with file open is disabled on your webserver. You might want to consider using Curl instead.