Welcome Guest ( Log In | Register)



 
Closed TopicStart new topic
> Error When Using file_put_contents(), failed to call to undefined function
electriic ink
post Aug 24 2005, 03:57 PM
Post #1


Incest is a game the whole family can play.
Group Icon

Group: [MODERATOR]
Posts: 1,232
Joined: 11-February 05
From: Heaven
Member No.: 3,709
myCENT:53.83



Hey all, I decided to write a script which writes some text to a file, but I have a problem when I execute the script, I get a fatal error:

QUOTE(homepage)
Fatal error: Call to undefined function: file_put_contents() in /home/cmatcme/public_html/afile.php on line 55


This is the code I'm using to write the file:

CODE
$ipfnsdoc = "/home/cmatcme/public_html/afolder/afile.txt";


if (!is_readable($ipfnsdoc)) {

echo "File cannot be read";
$stopload = 1;

}

if (!is_writable($ipfnsdoc)) {

echo "<br>\nFile cannot be written to";
$stopload = 1;

}

if (!$stopload == 1) {

$da_contents = file_get_contents($ipfnsdoc);

if ($da_contents == NULL) {

$da_contents = 0;

}

$towrite = $da_contents + 1;



file_put_contents($ipfnsdoc,$towrite);

}


I've read php.net's documentation on the function and to be honest, I can't understand half of it, so can anyone please tell me what I'm doing wrong?
Go to the top of the page
 
+Quote Post
rvalkass
post Aug 24 2005, 05:58 PM
Post #2


apt-get moo
Group Icon

Group: [MODERATOR]
Posts: 2,232
Joined: 28-May 05
From: Devon, England
Member No.: 7,593
Spam Patrol
myCENT:64.27



First check that you have CHMOD 777 to the file and the folder it is in, which often requires moving it to a different folder of its own. There may also be a problem with the path /home/cmatcme/public_html/afolder/afile.txt

As far as I am aware, if the PHP script is in /home/cmatcme/public_html/afolder/ then you would write the path as just afile.txt
I think it works just like HTML paths. You never put the literal file path in HTML, so you don't in PHP. Try changing it and see if it helps.
It doesn't matter that you don't understand the docs smile.gif , you don't need to. You are using the function correctly as it is.
Go to the top of the page
 
+Quote Post
electriic ink
post Aug 24 2005, 06:53 PM
Post #3


Incest is a game the whole family can play.
Group Icon

Group: [MODERATOR]
Posts: 1,232
Joined: 11-February 05
From: Heaven
Member No.: 3,709
myCENT:53.83



Both the directory "afolder" and the file "afile.txt" are have 777 permissions. The file has the full url set because it's part of a page header file and so will be included in all files which will be in many different directories. Seeing as I don't have any subdomains or folders which require the inclusion of this file yet I'm gonna try anyway smile.gif

======

No luck sad.gif Same error. I know the file exists and permissions are set because if they weren't is_readable() and is_writable() would pick those errors up.

The contents of $towrite before it is set to be written into afile.txt is 1 and $ipfnsdoc should be the same as when it was set earlier on (afolder/afile.txt).

I'm glad I've used the function correctly but also confused because if I am, how comes the error has arisen?
Go to the top of the page
 
+Quote Post
truefusion
post Aug 25 2005, 07:19 AM
Post #4


Ephesians 6:10-17
Group Icon

Group: [MODERATOR]
Posts: 1,978
Joined: 22-June 05
From: somewhere... Where am i?
Member No.: 8,528
myCENT:18.27



I think i know what the problem is. I looked up file_put_contents, and it said it's only for php5+, and i dont think Trap17 has that version installed. I think trap17 has v4.3.x. That's why you've been getting errors. You'll have to do it the old fashion way, with fopen, fwrite, and fclose.
Go to the top of the page
 
+Quote Post
electriic ink
post Aug 25 2005, 09:30 AM
Post #5


Incest is a game the whole family can play.
Group Icon

Group: [MODERATOR]
Posts: 1,232
Joined: 11-February 05
From: Heaven
Member No.: 3,709
myCENT:53.83



That's probably it. I've tried using the fopen(), fwrite() and fclose() procedure and it works. Thank you truefusion and rvalkass for helping me smile.gif.

My problem has been solved so I will lock the topic. If you wish the topic to be reopened then please report the topic with a good reason...

//Locked
Go to the top of the page
 
+Quote Post

Closed TopicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Getting List Of Directories And Files Using Php(6)
  2. Script: Php Jukebox(6)
  3. Trouble With Emailer.php(6)
  4. Parse: Error Unexpected T_lnumber(4)
  5. How To Use A Link To Call Function In Php?(8)
  6. Include File.php?id=something(13)
  7. How Good Is This Data Cleaning Function?(2)
  8. Mail() Clone(5)
  9. The Best Zip Function(1)
  10. How To Check If Fsockopen Function Is Enabled?(2)
  11. File Upload(1)
  12. T_string Error Please Assist(5)
  13. No File Extension(3)
  14. Php And Flash Image Gallery(5)
  15. Arrays Outside A Function(3)
  1. File Checker-how To Check File Whith Html Through Html?(2)
  2. Php Objects: Catchable Fatal Error(4)
  3. Script Help Required: Undefined Variable(3)
  4. Updating Php File Through A Web Form(5)
  5. Endif function?(6)
  6. Need Some Help In File Browser(8)
  7. Php Configuration File(16)
  8. Mysql Error(3)
  9. PHP Function To Add Previous and Next Page Feature(5)
  10. Linux/ Apache /mod_rewrite Issue(4)
  11. Search Engine/ Function(0)
  12. Getting Php Error On Oscommerce(3)
  13. Php - Fetching Random Line From A Text File(0)


 



- Lo-Fi Version Time is now: 21st November 2008 - 02:50 PM