Avatar of WGE_JMM
WGE_JMM
 asked on

how do i enable file_get_contents() & file_put_contents()

Hi guys,
here's probably an absolutely stupid question, but how do i enable file_get_contents()
and, file_put_contents()?

i require it for a social sharing website on our server, but our network engineer isn't in and i couldn't find anything on google that detailed how to actually enable it, i read it comes disabled in php5.

any advice would be amazing!

Thanks!
PHPWeb ServersWeb Development

Avatar of undefined
Last Comment
WGE_JMM

8/22/2022 - Mon
Beverley Portlock

It is not disabled by default in PHP5 but it may be on your server. There are two possiblities:

1) It does not work with either local or remote files - this indicates that it may be in the disabled_functions list in PHP.INI preventing its execution, or

2) It works for LOCAL files but not for REMOTE files. This is caused by allow_url_open being disabled in PHP.INI

http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen


Look in PHP.INI or run phpinfo() and look for allow_url_open and disabled_functions
WGE_JMM

ASKER
allow_url_fopen is enabled, and there is no disabled_functions in my php.ini.
i was under the impression that Fopen is different to File_getfile_put?

here's a link to my phpinfo(), most of it is just gibberish to me though!
www.wge.com.au/phpresult.php

Beverley Portlock

"there is no disabled_functions in my php.ini."

Sorry - my fault. It is disable_functions not disableD_functions, but it is empty in any case. From looking at that PHP.INI I would expect file_get_contents to work.

What do you get when you try using it?

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
WGE_JMM

ASKER
there is a share this on: feature on this page www.wge.com.au/www2 that doesn't work. the programmer of the page assured me it was because of file_get_contents and file_put_contents
Beverley Portlock

OK - your programmer may be partly correct. file_put_contents, generally speaking, cannot be used with remote servers because you cannot write to a file via Apache or IIS

file_get_contents can be used to retrieve HTML and other stuff from a remote web server but it often fails because the server may require logins or ID cookies or the remote machine may redirect your 'get' request elsewhere. It is for these reasons that you are far better off using PHP cURL to retrieve remote content (see http://www.php.net/curl for info and examples).

According to phpinfo() your error log is at C:\Windows\temp\php-errors.log so have a look in there and see if there are any errors relating to file_get_contents
ASKER CERTIFIED SOLUTION
groone

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Beverley Portlock

Good point groone - When using PHP you should always use / rather than \ as PHP will sort it out for you and translate the file separator. Using backslashes is not worth the pain.

Alternatively use the pre-defined constant PATH_SEPARATOR
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
WGE_JMM

ASKER
thanks, when i moved the site to the root directory and used forward slashes it worked! knew it had to be something simple!