issue with fopen on google app engine - php

I'm having the issue with fopen() on google app engine. Works normal 3-4 times and than this response from server.
Message: fopen(https://website_url/image_name.png): failed to open
stream: Connection closed.
Any idea how to troubleshoot what happened and why?
$image = "https://website_url/image_name.png";
$f = fopen($image,'rb');
php ini has allow_url_fopen = On

First make sure you have the correct path.
You need to give fopen the full path of the file, and you don't need chdir() at all. Try this version:
$path_to_file='url';
$fh = fopen($path_to_file.$filename, 'w') or die('Permission error');

Related

How to troubleshoot and get fopen()to work in php5?

I've searched as hard as I can, and have been stuck on what seems like such a simple issue.
I'm trying to use fopen() in php to create a simple txt file. My code is as follows:
$myfile = fopen("text.txt", "w") or die("Not Working");
But No matter what I've tried it won't work.
I use Godaddy hosting; plesk on windows.
allow_url_open is on.
and open_basedir is set to none.
I've confirmed this with phpinfo().
I read somewhere that perror can be used, I've tried using it in this context and it doesn't output anything:
$myfile = fopen("text.txt", "w") or perror("error");
I have display_errors set to on.
I'm really racking my brain on what else to try. GoDaddy support was useless.
Any advise on troubleshooting or what else my problem could be based off this information would be very helpful.
Thanks!

Unable to use php functions on hostgator server

I write a php script and run it on hostgator server and it is giving this error:
Warning: file_get_contents(
http://affiliates.kissmyads.com/stats/lead_report.json?api_key=AFFRd3xa8hRB3xOj7KsPnmQhlFYgNE&start_date=2014-06-24&end_date=2014-06-24)
[function.file-get-contents]: failed to open stream: No such file or
directory in www/barpy-money.in/app/kissmyads.php on line 10
It is unable to load function file-get-contents(). I am using this function directly in my program. When I run this code in joomla article it works fine but on server it gives error. Can anyone tell me why this is happening?
This is my code:
<?php
require_once 'include/DB_Connect.php';
// connecting to database
$db = new DB_Connect();
$db->connect();
$url = ' http://affiliates.kissmyads.com/stats/lead_report.json?api_key=my_api_key&start_date=2014-06-24&end_date=2014-06-24';
$result = file_get_contents( $url ); // line number 10
echo '<pre>';
print_r( json_decode( $result ) );
echo '</pre>'; ?>
php.net documentation for this function has a tip at the bottom:
Tip
A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename.
In order to do this you will need to edit your php.ini file. Per hostgators instructions:
allow_url_fopen, how to enable
This can be done via your php.ini file by adding the following line:
allow_url_fopen = On
The php.ini file is where you declare changes to your PHP settings. You can edit the existing php.ini, or create a new text file in any subdirectory and name it php.ini.
http://support.hostgator.com/articles/specialized-help/technical/allow_url_fopen-how-to-enable
Also you have a space in the $url variable before your http.
check you have enabled in your php.ini
allow_url_fopen = on
try to check phpinfo()
or may be url doesn't exist you given in file_get_contents() also do not add spaces in url you need to set like:-
$url = "http://affiliates.kissmyads.com/stats/lead_report.json?api_key=my_api_key&start_date=2014-06-24&end_date=2014-06-24";
$result = file_get_contents($url);

Warning on loading XML data

I am using following code to get current time (hours) in Los Angeles
$response_xml_data = file_get_contents('http://www.earthtools.org/timezone-1.1/34.05223/-118.24368');
$data = simplexml_load_string($response_xml_data);
$dt = new DateTime($data->localtime);
$time = $dt->format('H:i:s');
list($hour, $min, $sec) = explode(':', $time);
echo $hour;
This code is working fine offline, but i am getting following warning message when i put this file online:
Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in [PHP file name and line number]
Warning: file_get_contents(http://www.earthtools.org/timezone-1.1/34.05223/-118.24368)
[function.file-get-contents]: failed to open stream: no suitable wrapper could be
found in [PHP file name and line number]
It looks like i am using a wrong method to read XML data, please suggest?
This means that on the server you call "online" the HTTP wrapper is disabled for file functions in PHP.
I believe this is caused by having php's allow_url_fopen setting disabled on your server. This prevents the https wrapper from being available, or something like that.
You can enable allow_url_fopen in your php.ini file and this should error should go away. Not sure of other repercussions of this so know what you are changing before you change it.
Ref: http://php.net/manual/en/filesystem.configuration.php
Basically, you just need to override php default configuration open php.ini
allow_url_fopen = ON

PHP Using Scandir with and External URL - Not Implemented

I'm having some trouble using scandir - I have it working fine on one site but now I'm wanting to scan the same directory on that site but from a different website.
I'm using the following code:
array_diff(scandir('http://sub.domain.co.uk/folder/folder/'), array('.', '..'));
and I get this error:
Warning: scandir(http://sub.domain.co.uk/folder/folder/): failed to open dir: not implemented
I've had a Google but brought up very little - I've tried enabling directory listing on the external site and allow_fopen_url is enabled as well.
I'm stumped, any help with this one?
Assuming you have the ftp extension loaded in PHP (PHP: FTP), you could:
$connect = ftp_connect($ftp_server);
$login_result = ftp_login($connect, $username, $password);
$contents = ftp_nlist($connect, ".");
print_r($contents);
This turned out to be a loop back problem, I was trying to scan a a folder on the same domain which was not allowed with my host.
I've had to introduce a 'state' to deal with this which says whether the software is live or not (because the software, once live, will actually point to a different domain).

load xml file in php - missing access rights?

I want to read a XML file from a certain link with the following code
$filename = 'http://XXXXX/rss.xml';
$xml = simplexml_load_file($filename);
When I try, I get the following error messages:
wrapper is disabled in the server configuration by allow_url_fopen=0
failed to open stream: no suitable wrapper could be found in
I/O warning : failed to load external entity
Whats the problem? Can it be that the server doesn´t support simplexml_load_file?
When allow_url_fopen is set to 0, you have no permissions to acces URL objects like files. Read official manual for more information.
You can not change this value via .htaccess, so you have to set allow_url_fopen=1 in your php.ini file. If you're using a shared hosting or some kind of it, you should contact hosting technical support and describe them your problem.

Categories