Use PHP to Create a file and make it writable

They have: 426 posts

Joined: Feb 2005

So my application is writing to a CSV file. However, if the amount of lines in the CSV file exceed a certain amount I want to create a new CSV file and start writing to this.
Checking and creating the file is fine, I just cant write to it. After some searching noticed that there are restricts to making files writable (CHMOD()) using PHP.
Can anyone advise what I should do in order to achieve this?

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

Depends on your setup with your hosting company.

You could make a directory that is writable by the apache process (usually apache or nobody), then PHP would be able to create new files.

If you go this route, you may want to set apache to not directly feed files from it.


Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.