Jump to content

Recommended Posts

Posted

I'm having trouble creating and writing a file using a very simple PHP script that I have written. I need this file to store a counter value. The file may not exist when the script runs. The code runs correctly on my local PHP installation using EasyPHP but it will not create the files on the TCH server.

 

The main problem seems to be that I cannot actually create a file using the php function fopen("myfile.txt","w"). The most basic test was to try and create the file in the same directory as the script is running and this fopen() failed.

 

The directory/folder does not have a .htaccess file in it and the directory is chmod to 755 to allow read/writes. I am running in a subdirectory but I don't think the root has a .htaccess file.

 

Any suggestions would be really welcome!

 

- Chris

Posted

PHP runs under the webserver user "nobody", not as your account. You will need to set the directory you want to write to as 777 so that the webserver can write to it (and for that reason I'd recommend a subdirectory, and not the directory your scripts are sitting in).

 

Welcome to the forums, too, ois!

Posted

Thanks for the clarification on the chmod (and the welcome messages). My current file placement is only for testing until I can sort this problem out, after that I'll really lock it down using subdirs and permissions.

 

I suspected 755 might not be high enough but how can I chmod to 777? Both the Cpanel file manager and SmartFTP will let you _try_ to set 777 but always revert back to 755. It is fairly normal to restrict this to 755 with most shared hosting accounts so I figured this should work.

 

Any other thoughts?

 

Chris

Posted
Both the Cpanel file manager and SmartFTP will let you _try_ to set 777 but always revert back to 755.

 

The cPanel file manager will allow you to set it to 777, but you have to do it by selecting the check boxes, not by entering the numbers (the checkboxes override the numbers). Just click the write access for group and world (you really only need world) and save.

Posted

Mike

 

Chmod did "take" and the script finally works with 777 permissions.

 

Thanks for clarifying this and the quick reply.

 

Chris

Join the conversation

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

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...