Jump to content

[SOLVED] file_put_contents()?


ag3nt42

Recommended Posts

Hi all,

 

I'm trying to use this function and I can't seem to get it to work..

 

file_put_contents()

 

here is my code:

 

$Cinfo ="This bites";
echo file_put_contents("Cinfo.php",$Cinfo,FILE_APPEND);

 

everytime i try and use it i'm getting this error

 

Warning: file_put_contents(Cinfo.php) [function.file-put-contents]: failed to open stream: Permission denied 

 

I have the permissions set to 7777 on this "Cinfo.php" file so i do not know why its sayin denied permission.

 

thanx,

 

ag3nt42

Link to comment
Share on other sites

ok i've chmod my whole frikin website and it still doens't work

 

code i'm using:

 

<?php
$file = fopen("Cinfo.php","w");
echo fputs($file,"This sux donkey ballz");
fclose($file);
?>

 

errors i'm getting:

 

Warning: fopen(Cinfo.php) [function.fopen]: failed to open stream: Permission denied in mypath/tester.php on line 4

Warning: fputs(): supplied argument is not a valid stream resource in mypath/tester.php on line 5

Warning: fclose(): supplied argument is not a valid stream resource in mypath/tester.php on line 6

Link to comment
Share on other sites

i'm open to any suggestions here.. it doesn't even have to be the same way i'm doing it..

 

all i need is for to store some data on a txt file. And occasionally read it back into my code.

 

 

REPLY [jonsjava]

 

I chmod it again to 666 this time as well as the folder same exact error messages...

how else to chmod then right click properties type in the 666 hit apply and done..

 

my ftp tells me attributes changed successfuly

Link to comment
Share on other sites

Guest Xanza

Try this:

 

<?php
$file = fopen("Cinfo.php","a+"); //maybe this will help
echo fputs($file,"This sux donkey ballz");
fclose($file);
?>

 

Other than that the only thing I can think of is your server has a problem with either fopen, or it's PHP install or something crazy like that.

Link to comment
Share on other sites

well i guess i'm just royaly screwed then, cuz I change the permissions then refresh and they are there for like a split second then its back to 0 no permissions checked... my user name for ftp is the same as my user account for windows inwhich I am admin, ftpuser, everyone. I have full control permission set with IIS5 on the entire webfolder directory.

 

and nothing seems to be working. It still will not write to the file and I still get the exact same error messages..

 

I refuse to believe this can't be fixed but, there has got to be something we are missing here.

Link to comment
Share on other sites

ok now i'm extremely irritated...

 

used this code to check for writeability,

 

<?php

chown("Cinfo.php","ag3nt42");

echo fileowner("Cinfo.php"); 

$file = "Cinfo.php";
if(is_writable($file))
  {
  echo ("$file is writeable");
  }
else
  {
  echo ("$file is not writeable");
  }

?>

 

 

returns:

 

0

Cinfo.php is writeable

Link to comment
Share on other sites

it claims the owner is 0 I tried using posix_getpwuid() to generate an actual name but apparently those functions are only available on unix based platforms

 

 

ag3nt42 is my system name yes.

i have full permission on everything.. i'm part of the admin group and ftp group

Link to comment
Share on other sites

does anyone know of another way to do this:

 

basically all i need is to take some form data and toss it into a txt file. so it can be read back in later.

 

for example:

 

I am creating an install file and I want to store the database connection info into a txt file so that

my code can grab the info when it is needed. The information is obviously not static so how else can I do this?

Link to comment
Share on other sites

can anyone tell me how this is working?

 

I had to go through all this trouble to get php to write to my test file...

 

meanwhile when I installed phpBB3 forum they are able to write to their config.php file without having to alter permission like  I had to...

 

on top of that.. when i went in to check the permissions on the file.. it had the same permissions as my Cinfo.php file BEFORE i altered them.

 

So my questions is how is phpBB able to do this yet I cannot?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.