Forum Moderators: coopster

Message Too Old, No Replies

php help needed - unrecognised function

would it be an older version?

         

chrisandsarah

12:05 pm on Aug 2, 2003 (gmt 0)

10+ Year Member



Hello

I'm in the process of updating my site with a new database and php file that drives it. The guy who does my php/db work is unreachable so i cant get him to help. I'm coming up with this:

Fatal error: Call to undefined function: file_get_contents() in /usr/local/mydomainname.com/public/functions.php on line 16

Would it be that my host has an older version of php installed that cant recognise this function?

thanks for any help

jaski

12:32 pm on Aug 2, 2003 (gmt 0)

10+ Year Member



I think your answer is correct. This function is available in PHP 4.3 and after .. which makes it pretty recent.

chrisandsarah

12:41 pm on Aug 2, 2003 (gmt 0)

10+ Year Member



ok thanks jaski
that leaves me stumped then. i have no knowledge of php and the guy i use seems to have gone away.
Does anyone know of a function that does the same thing but works for older versions?
or is it possible for me to define the function on my php page?

thanks

hakre

1:20 pm on Aug 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hi!

you can write the function on your own and put it to your script, so you won't get anymore errors with your php version. if you upgrade later on, you can simly delete that function, you main script will continue to work with no problems:


function file_get_contents($filename, $use_include_path=0) {
/* reads out the complete contents of $filename */
$handle = fopen ($filename, "r",$use_include_path);
$contents = fread ($handle, filesize ($filename));
fclose ($handle);
return $contents;
}

you can use this function then as described in the php manual.

-hakre

daisho

2:38 pm on Aug 2, 2003 (gmt 0)

10+ Year Member



Or as a slightly more bullet proof solutions you can test to is if the function exists:

if(!function_exists('file_get_contents') ) {

function file_get_contents($filename, $use_include_path=0) {
/* reads out the complete contents of $filename */
$handle = fopen ($filename, "r",$use_include_path);
$contents = fread ($handle, filesize ($filename));
fclose ($handle);
return $contents;
}

}

This way if it's not there it will be created. If you upgrade PHP then you *SHOULD* remember to take it out but atleast your site will not break.

Though I would sugest to upgrade you PHP if at all possible since there were quite a few security patches that were fixed in 4.3.1.

daisho.

chrisandsarah

5:44 pm on Aug 2, 2003 (gmt 0)

10+ Year Member



Thanks for your help, but for some reason it still not working.

Is it as simple as cutting and copying the code you gave me into the functions.php? its this file that actually calls the function.
the only other php file is the index.php which calls on functions.php to do all the work

Cheers

chrisandsarah

5:51 pm on Aug 2, 2003 (gmt 0)

10+ Year Member



i get this error..

Warning: stat failed for [madeupdomain.com...] (errno=2 - No such file or directory) in /user/local/home/vhosts/mydomain.com/public/mydirectory/functions.php on line 10

Anyone interested in some work?

vincevincevince

6:02 pm on Aug 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



cut the ? off the end of your filename - that's what's causing the problem I think. if you don't already know how:

$filename=preg_replace("/\?.*^/","",$filename);

that will neatly trim off any arguments etc - I use it for include()s

jaski

4:39 pm on Aug 3, 2003 (gmt 0)

10+ Year Member



>>No such file or directory) in /user/local/home/vhosts/mydomain.com/public/mydirectory/functions.php on line 10

Is there a filename on line 10 without absolute path .. if so try giving full path of the filename ie. - /user/local/home/vhosts/mydomain.com/public/mydir/myfile