cmatcmextra
Aug 24 2005, 03:57 PM
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?
Comment/Reply (w/o sign-up)
rvalkass
Aug 24 2005, 05:58 PM
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  , you don't need to. You are using the function correctly as it is.
Comment/Reply (w/o sign-up)
cmatcmextra
Aug 24 2005, 06:53 PM
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  ====== No luck  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?
Comment/Reply (w/o sign-up)
truefusion
Aug 25 2005, 07:19 AM
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.
Comment/Reply (w/o sign-up)
cmatcmextra
Aug 25 2005, 09:30 AM
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  . 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
Comment/Reply (w/o sign-up)
(G)viethak
Aug 16 2009, 03:15 AM
Fixed it
Error When Using file_put_contents()
Add this code on top files
<?php
if(!function_exists('file_put_contents')) {
function file_put_contents($filename, $data, $file_append = false) {
$fp = fopen($filename, (!$file_append ? 'w+' : 'a+'));
if(!$fp) {
trigger_error('file_put_contents cannot write in file.', E_USER_ERROR);
return;
}
fputs($fp, $data);
fclose($fp);
}
}
?>
-reply by viethak
Keywords: fatal error: call to undefined function: file_put_contents()
Comment/Reply (w/o sign-up)
Similar Topics
Keywords : error, file, put, contents, failed, call, undefined, function
- Php - Fetching Random Line From A Text File
and displaying it using AJAX/iframe (0)
Getting Php Error On Oscommerce
(3) ok i installed oscommerce on my hosting and i got a template that im trying to isntall on it but
when i go to the install folder it says Server Requirement Error: register_globals is disabled in
your PHP configuration. This can be enabled in your php.ini configuration file or in the .htaccess
file in your catalog directory. and register_globals is enabled in .htaaccess i cannot find php.ini
sumone PLZZZ help me!!!....
Search Engine/ Function
(0) Hi there, can anyone please give me a tutorial or something on how to create a search engine sort of
thorugh PHP. I don't have any background knowledge of PHP but im trying to learn it so please
could someone help! Btw, im talkinng about a search engine which you type in a url website and wen
you click on go it will go straight o that website THROUGH another search engine. For example, my
friend, not saying me, has a sort of search engine where he just types in the url of the website and
when he clicks search it automatically goes the website homepage THROUGH phpr....
Linux/ Apache /mod_rewrite Issue
Error when accessing a file (4) running on Ubuntu 8.04 with an XAMPP - php5.2.5, Apache 2., etc Getting this error when I try to
access an sNews CMS which requires mod_rewrite and is installed locally: QUOTE Apache/2.2.8
(Unix) DAV/2 mod_ssl/2.2.8 OpenSSL/0.9.8e PHP/5.2.5 mod_apreq2-20051231/2.6.0 mod_perl/2.0.2
Perl/v5.10.0 configured -- resuming normal operations /opt/lampp/htdocs/jim/snews/.htaccess:
RewriteBase: argument is not a valid URL /opt/lampp/htdocs/jim/snews/.htaccess: RewriteBase:
argument is not a valid URL Using this link: http://localhost/jim/snews/snews16_ema....
PHP Function To Add Previous and Next Page Feature
useful php function (5) CODE function navigationbar($start_number = 0, $items_per_page = 50, $count) { // Creates a
navigation bar $current_page = $_SERVER ; if (($start_number $start_number = 0;
} $navbar = ""; $prev_navbar = ""; $next_navbar = ""; if ($count >
$items_per_page) { $nav_count = 0; $page_count = 1; $nav_passed = false;
while ($nav_count // Are we at the current page position? if
(($start_number $navbar .= " "; $nav_passed = true; ....
Mysql Error
(3) ok i need some more help from the wonderful coders here at Trap. I'm almost done with my CMS
script, but i'm having a problem with the installer.php file, when it trys to inseret the user
data into the database i keep getting the following error: CODE mySQL Error: You have an error
in your SQL syntax; check the manual that corresponds to your MySQL server version for the right
syntax to use near ';INSERT INTO `members` (`id`, `name`, `username`, `password`, `email`,
`title`) ' at line 1 the code that is being excuted by the php file is this: C....
Php Configuration File
"config.php" (18) I did create this topic mainly because I want to know everything about that configuration file. I
will post other replies if I want to know more depending on your experience. Is this code correct
for that file: CODE $host="localhost"; $dbname="XXX"; $dbuser="XXX"; $dbpass="XXX";
$connection=mysql_connect($host, $dbuser, $dbpass) or die(mysql_error()); mysql_select_db($dbname)
or die(mysql_error()); ?> Add your suggestions or improve it.....
Need Some Help In File Browser
listing all sub folders and files in them. (8) Hey I want to create a very simple file browser, so that, it reads all the sub-folders which are
places in a directory, and the files inside the sub-folders (It reads only files inside sub-folders
and list them in simply. ) Also, it creates a directory (any name) inside each sub folder. My
Following code reads on the files inside the main directory, it does not read the files inside the
sub-folders.. I appreciate any help. CODE $path = "./"; $dir_handle = @opendir($path) or
die("Unable to open $path"); while ($file = readdir($dir_handle)) { if($file == "." || $fil....
Endif function?
(6) As you get noticed before, I am studying PHP in examples like using the tutorials as well as books
itself. Through my readings, I get this function CODE a lot of times. So, what do you mean
by this function, and what does it do exactly?....
Updating Php File Through A Web Form
(5) Hello, i'm not sure if this can be done with php or not but what i need is a way to make an php
file that have an html form on it and it will take the info you put in to that form and write it to
an existing php file, for example: if i have the file news.php and the file news_update.php. if you
went to news_update.php you would get an form with a text area for you to write a new addition for
the news.php file and when you hit submit it will add what you typed in the form to the file
news.php. If this is going to be a big code or a hard one to make but some one think....
Script Help Required: Undefined Variable
A fault I cannot spot in PHP (3) Hi, when running a PHP script I keep getting the error: QUOTE Notice: Undefined variable: bret
in c:\program files\easyphp1-8\home\poll.php on line 294 Notice: Undefined variable: bret in
c:\program files\easyphp1-8\home\poll.php on line 294 (And, yes, I get it twice). The code
related to the variable is as follows: CODE function LogString($string,$type) {
$t_log = "\n"; $t_log .= $this->globaldata->server_vars ."|";
$t_log .= date("Y-m-d h:i:s A|"); $t_log .= "$type| "; $string =
str_replace("\n","\\n",$s....
Php Objects: Catchable Fatal Error
There is a weird problem with objects in php 5.2.2 (4) in php 4.4.7 my code seems to be ok but in later version 5.2.2 i get this error Catchable fatal
error: Object of class mission_rank could not be converted to string in
/Applications/xampp/xamppfiles/htdocs/nexus/includes/forms/cn_reload.php on line 41 cn_reload.php
include('../class/userClass.php'); session_start(); $app_user =& $_SESSION ; if
($app_user->character != false) { $race_letter =
array('H','E','T','M','G'); $cn_id = 0; foreach
($app_user->character as $character) { // div container ....
File Checker-how To Check File Whith Html Through Html?
(2) edit:sorry for the mistake it is php not html and its with not whith my code checking script= CODE
$file = '$CHECK'; if (file_exists($file)) { echo "The file $filename exists"; } else
{ echo "The file $filename does not exist"; } ?> my question is how to check the file whith
html example:on a page a text box is provided and a button the user writes a file name (or website)
the user clicks on the submit button then it checks and show it (with the code above) i got the
code CODE $filename=$_POST ; if (file_exists($filename)) { echo "The....
Arrays Outside A Function
Need to have arrays available to all functions. (3) I've got a bunch of arrays that i want to use for more then 1 function. when i declear the
arrays outside a function i cant use it in a function. This code was originally written in
javascript by another person but since I plan to use it and extend it with php I had to change it
from javascript to php code. In the javascript code the arrays were decleared outside the functions
with 'var arrayname' I read somewhere that declearing javascript variables with
'var' gives it global access. Any ideas on how I can go about declearing 1 set of these
arrays t....
Php And Flash Image Gallery
Need some help in creating or editing an xml file while viewing some o (5) Hello there and thanks for the helping hand you are offering. PHP newbie here! /ph34r.gif"
style="vertical-align:middle" emoid=":ph34r:" border="0" alt="ph34r.gif" /> So here is my problem:
On my website I have a flash image gallery.The way the gallery works is by uploading pictures in a
folder and editing? an xml file.(pics.xml) where it adds the following code when you upload a
picture: CODE etc... Now I have users that upload products they sell on the
website or they advertise their business(hotels, jewellers, car resellers,...) So for eve....
No File Extension
(3) On MediaWiki, the URL of the content is http://YOURWIKI.com/index.php/Blah Is it possible to
create a page or two that doesn't have a file extension? If so, how is it done?....
T_string Error Please Assist
(5) I have unexpected t_strings in 3 lines they are CODE // $Header$ //this script may only be
included - so its better to die if called directly. if (strpos($_SERVER ,basename(__FILE__)) !==
false) { header("location: index.php"); exit; } /* A basic library to handle a cache of some
Tiki Objects, usage is simple and feel free to improve it */ class Cachelib { var $folder;
function Cachelib() { global $tikidomain; $this->folder = "temp/cache"; if
($tikidomain) { $this->folder.= "/$tikidomain"; } if(!is_dir(....
File Upload
File upload (1) I need to add a facility on my customer's website so his clients can send him jobs, typically
5mb - 50mb. I've looked around the web and researched this, and tried a few tests (failed), but
my brain's beginning to hurt. Could someone please tell me the best way to go about this,
please. The site is done in Flash, but I'm sure a link to an html page would be ok if necessary.....
How To Check If Fsockopen Function Is Enabled?
(3) Hi, I have VPS (virtual private server) and I have access to php.ini file. Is there any script that
will show that fsockopen function is enabled or where do I have to enable it? Searched google and
here and couldn't find anything. Thanks! ....
The Best Zip Function
(1) hi my 6th code is very useful, you can zip your file by this: CODE class dZip{ var
$filename; var $overwrite; var $zipSignature = "\x50\x4b\x03\x04"; // local file header
signature var $dirSignature = "\x50\x4b\x01\x02"; // central dir header signature var
$dirSignatureE= "\x50\x4b\x05\x06"; // end of central dir signature var $files_count = 0;
var $fh; Function dZip($filename, $overwrite=true){ $this->filename =
$filename; $this->overwrite = $overwrite; } Function addDir($dirname,
$fileComments=....
Mail() Clone
A PHP mail() function clone (5) A lot of free web hosts have disabled the mail() function so you cannot send emails using PHP. Does
anybody know of a script that makes a function "like" mail but is able to be installed in a web
accessible directory and called included into another script and called like that? Or maybe you know
how to make such a function? I just really need to find a way around the free hosts turning of the
mail() function. I need to figure out a way to send emails.....
How Good Is This Data Cleaning Function?
(2) Hi all, this is my first function and as part of a script and i just want to know a couple of
things. here is the code for the function: CODE function clean($dirty_string) {
$muddy_string = stripslashes($dirty_string); $murky_string = strip_tags($muddy_string);
$clean_string = htmlentities($murky_string); }; ?> So the first thing is how secure is it?
the script this will be used in connects to a database and sends an email so it needs to stop SQL
injections and any email abuse it might cause, also the data stored in the database will be usaed as
par....
Include File.php?id=something
using the include() function (13) Well, I am making a full CMS system for my site, and want to make the index.php file to include the
view.php?id=1 file. I tried with this code, but it didn't work: CODE This is the error
I get: CODE Warning: main(view.php?id=1) : failed to open stream: Invalid argument in
C:\server\xampp\htdocs\test\index.php on line 1 Warning: main() : Failed opening
'view.php?id=1' for inclusion (include_path='.;C:\server\xampp\php\pear\') in
C:\server\xampp\htdocs\test\index.php on line 1 So what can I do?....
How To Use A Link To Call Function In Php?
(9) The title says it all, really. How do you call a function using in PHP? I'm doing a project
and I stumbled upon this problem. I don't want to use query string in the href part like
since that would mess up the other part of my code. Can anyone pleae help me? I've pasted the
code below. /smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /> Thanksh.
CODE function display($x){ //coding goes here. } ?> Display itmes ....
Parse: Error Unexpected T_lnumber
php parse error when running script (4) Hi. I've just created a php script. The main object of the script is to delete some old files
and replace it with a new file with some new content, effectively moving the contents from one file
to another. These are the first 50 lines of the file: /* Calculate For The "A" Group - The
Latest Games ID */ $a_B = 002; while(file_exists("a_" . $a_B . ".dat")) { $a_B++; }
$new_page_contents = " " . $_POST . " " . $_POST . " include
\"/home/cmatcme/public_html/footer.php\"; ?> "; $a_stream = fopen($a_B . ".cmat", "w+");
fwri....
File Uploading Issues
(5) i have never tried to have files uploaded and i am still not able to do so. here is the codes that i
am using right out of the php manual and it still isnt working. i have also listed the
warnings/errors listed on the resulting page. my permissions are set to 777 also. i have a folder
set up on my server as "uploads". i am however not sure if i have a default temp folder on my
server. can anyone help me figure out what i am not doing correctly or what my next step is? this
is the form that i am using: html Code: CODE Choose a file to upload: ....
Trouble With Emailer.php
failed sending email error (6) Whenever someone registers at my forum, they get this error: Failed sending email :: PHP :: DEBUG
MODE Line : 234 File : emailer.php however, the account will be sucessfully registered. It is
weird because i did not change the original emailer.php at all. O__O||| anyone know whats up with
it?....
Script: Php Jukebox
A one file script! (6) This scripts is so simple, you dont need to edit ANY of it! All you have to do is make a folder
called 'songs' and put some audio files in it. Here is the whole page, I named it index.php
and put it in a folder called 'music': CODE PHP jukebox ©2005 Craig lloyd.
All rights reserved. Visit cragllo.com for more scripts --> /** * ©2005 Craig lloyd. All rights
reserved. * * Mod Title: Simple PHP Jukebox * Author: Craig Lloyd * Author
Email: cragllo@cragllo.com * Author Homepage: http://www.cragllo.com/ * Des....
Getting List Of Directories And Files Using Php
PHP Function for Directory and File List (6) is there a php function that lists the content of some folder.... example: /New folder new.txt
left.gif download.zip dc.exe ....so is there..? /rolleyes.gif' border='0'
style='vertical-align:middle' alt='rolleyes.gif' /> ....
Pages In 1 File
?? (10) I know its possible to put many pages inside 1 file. But how? Lets say you have a guestbook with
different pages for signing and viewing. How to make so those pages are in 1 file? /huh.gif"
style="vertical-align:middle" emoid=":huh:" border="0" alt="huh.gif" />....
Looking for error, file, put, contents, failed, call, undefined, function
|
Searching Video's for error, file, put, contents, failed, call, undefined, function
See Also,
|
advertisement
|
|