Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to use fopen and gettinfailed to open stream: Permission denied 1

Status
Not open for further replies.

Chomauk

Programmer
Jun 8, 2001
130
Hi, at one time this worked and now it doesn't. Can anyone tell me what I need to do to create a file in my directory. I'm using a webhost and here is the code:
Code:
<?php 
$ID = substr(uniqid("ID"),6);  
$data = "This is a new file entry!\n";   
$file = "Confirm_". $ID. ".php";
echo $file;

$file_handle = fopen($file,"w+");
fwrite($file_handle, $data);
   
fclose($file_handle);   
?>
That's if for now but I'm getting an error of
fopen(Confirm_3848f0f4a.php): failed to open stream: Permission denied for all three...fopen, fwrite and fclose.
I've read some stuff on chmod but don't understand(yes I'm a newbie). Can anyone tell me what I need to do to create a file?

thanks


"Failure is the tuition you pay for success."
~ Walter Brunell ~
 
Ok, here we go:
I am not an expert on this and am sure our Linux/Unix friends can help better.

CMOD values.
User (yourself)
read = 400
write = 200
execute = 100

Group
read = 40
write = 20
execute = 10

The rests (internet users?)
read = 4
write = 2
execute = 1

So if only you as logged in user should have read access make it: 400
read access for all: 444

Now say we all have read and write access (read = 4, write = 2 -> 4+2=6) : 666

All having all access (read=4, write=2 execute=1 -> 4+2+1=7): 777

So now go to your ftp program to make things easy and use the CMOD function in there (I find this easiest).

Good luck


JR
(In need of a cool signature)
 
Oh, might be a good idee to check if your file is actually there where you expect it to be [smile]

JR
(In need of a cool signature)
 
I don't want to ftp anything...what I eventually want to do is when a user enters my site and enters pertinent infomation I want to create a confirm php file and send it to the email address they provided so they can confirm their registration.

Am I even doing this right so far?

Thanks for explaining the chmod stuff, I understand that part better now.

"Failure is the tuition you pay for success."
~ Walter Brunell ~
 
Shouldn't the file be in the directory where I'm trying to create it? Since I don't specify a path and say the page creating the file is in say /html/thispath... shouldn't the new file be created in /html/thispath?

Gulp

"Failure is the tuition you pay for success."
~ Walter Brunell ~
 
Hiya,
ftp was not suggested to ftp anything, but programs such as WS-FTP happen to have a simple CMOD function coming with them [smile]

But I am sure there are many other ways to CMOD something.

As far as for the location...
I would indeed assume that what ever you use to create the file (I understand that is a separate script?) will put the file in the same directory as the script runs, but am not entirely sure.

SO why not just create a file using that script and check if it is there (using ftp or http whatever you fancy).

If it is there you solved that bit.
Set the CMOD and see what happens.
If you are in the wrong directory I would actually expect an error such as: Cant open thread blablabla...

Have fun

JR
(In need of a cool signature)
 
I'm trying to create the file with the fopen statement but getting the error I mentioned in the subject title. In my research I read about chmod but don't understand how it works with fopen.
I also read about the .htaccess file and php.ini file but can't get it work with those either.

Surely somebody has done this?

thanks

"Failure is the tuition you pay for success."
~ Walter Brunell ~
 
If you get a "permission denied" error when trying to create a file, the cause is nearly certainly that the user as which the web server runs does not have permission to write to the directory.





Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Seeing I don't have permission that means I cannot do anything about it...with .htaccess or php.ini or any other command?

"Failure is the tuition you pay for success."
~ Walter Brunell ~
 
It may or may not be the fact that you can't do anything about it.

Is this a hosted system, or your own machine?

If it is a hosted system, it is likely that a call to your hosting provider can clear up the permission problem.

If it's your own system, give your web server's user permission to write to the directory.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
It's a hosted system and my web host isn't reliable(Vaticus.com). Looks like I'm probably out of luck?

thanks

"Failure is the tuition you pay for success."
~ Walter Brunell ~
 
It's difficult to say.

I recommend first that you talk to your HSP to see what they can do for you.

Also, they may have an interface into your user space which you can use to set filesystem permissions. But again, you'll have to talk to your HSP to find out if and what that interface is.

On unix-like OSes, there's also the possibility of writing to the /tmp directory. All users have permission to write there.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
So in the tmp directory I can create php web pages for users to access and verify their email addresses?

Thanks.

P.S. I've written my host....::fingers crossed::

"Failure is the tuition you pay for success."
~ Walter Brunell ~
 
You didn't say that. You were just trying to write to a file.

Why aren't you producing the page on-the-fly and simply streaming it to the user?



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
hmmm I'm new at this so please forgive my ignorance, but "I didn't say what?" Maybe I'm going about it wrong.

How do I produce a page on-the-fly and stream it?

To explain in more detail. I have a registration page and after the user enters their info I want to automatically create a confirmation page and email the link to the user for them to click on. This will open that page and confirm their registration. After the confirmation I'd probably want to delete the confirmation page since it won't be needed anymore.

thanks

"Failure is the tuition you pay for success."
~ Walter Brunell ~
 
You didn't say you were going to be writing sensitive data to this file. The nature of the data adds new problems to the picture, particularly since you're going to need to keep one user from seeing the data of another.

In this particular case, under no circumstance would I write this to a file and send the file to the user. I would just dynamically create the page and send it to the user through the web server's connection to the browser.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I'm not writing sensitive data to the file. It's just a page being sent to the user to verify their email address. Sorry I didn't mention that. The data entered is stored on MySQL but the user has to click on the confirmation page to verify their email address.

"Failure is the tuition you pay for success."
~ Walter Brunell ~
 
It is still completely unnecessary to write anything to the filesystem. Just dynamically create the page as necessary and send it to the browser.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
OK thanks but how do I create the page dynamically since what I was trying to do is wrong?

"Failure is the tuition you pay for success."
~ Walter Brunell ~
 
I've done email address verification before.

The first stage was a script (call it script1.php) which if run with no input, produced a form in which the user could enter a username, password, email address and other information. That form submitted back to script1.php.

If script1.php was run with input names matching the form, the script verified and validated all user-input information. If the user's requested userid wasn't already being used in the system, if both entries of the password matched and if the input passed other checks, the script added the user's information to the database, sent a verification email to the user and produced a web page which told the user to expect the email.

The email contained a link with input values to another script (call it script2.php) which, when run, activates the user record and displays a page saying so.

Nothing was ever written to the filesystem.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top