URL file access -> PHP

software development

#1

Good morning
This is my first post on the forum, so please, be nice with me :slight_smile:

So i have a probleme with the php function fopen. I try to make a fopen on an ftp url, and the server answer me that the “URL file-access is disabled in the server configuration”.

Do you know how to enable it, because i really need this function!

PS: it works perfectly on me Xampp local server

Thanks a lot

Renaud


#2

[quote]Good morning
This is my first post on the forum, so please, be nice with me :)[/quote]
Good evening (well it is evening here :slight_smile: welcome to the forum.

The error message is correct. For security reasons, the default DreamHost PHP install has the allow_url_fopen option disabled. Unfortunately, this being shared hosting, you do not have access to the php.ini file to change this.

There are a number of ways to overcome this limitation. The first and probably the easiest, is to modify your code to use CURL.

http://www.wiki.dreamhost.com/index.php/CURL

Another option is to copy the PHP executable and php.ini file to your local directory and create/modify your .htaccess file to use this local version. You can then modify this local php.ini file to enable allow_url_fopen.

http://wiki.dreamhost.com/index.php/PHP.ini

The third option is much like the one above, but instead of copying the DreamHost PHP executable, you compile a custom PHP executable.

http://wiki.dreamhost.com/index.php/Installing_PHP5

Mark


Save [color=#CC0000]$50[/color] on DreamHost hosting using promo code [color=#CC0000]SAVEMONEY[/color] ( Click for promo code details )


#3

Thanks for replying
cURL seems to be cool, but i have one probleme!

when i try to give this kind of url :
ftp://login:password@host/folder/subfolder
it doesn’t work at all!

Can you help me ?


#4

[quote]when i try to give this kind of url :
ftp://login:password@host/folder/subfolder
it doesn’t work at all![/quote]
That is odd. I just tried the following code, copied from the wiki article, and it retrieved a text file from my ISPs FTP and displayed it correctly.

[color=#0000CC]<?php
$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, ‘ftp://username:password@myisp.net.au/test.txt’);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);

// display file
echo $file_contents;
?>[/color]

Mark


Save [color=#CC0000]$50[/color] on DreamHost hosting using promo code [color=#CC0000]SAVEMONEY[/color] ( Click for promo code details )


#5

Yes it’s true, it works! My probleme is another one on the same mini project ! I’m gonna post another thread for this problem :slight_smile:

Thanks a lot for helping me with cURL, it’s a very cool thing!


#6

Original:
when i try to give this kind of url :
ftp://login:password@host/folder/subfolder
it doesn’t work at all!

You have to specify a file, unless you’re pulling up a web directory through http, which has a default document. Upload a text doc to subfolder and point at it. I just tried, and it worked for me.

BC Tech
Team Shocker