When PHP accepts a file upload, it saves the file into the temporary directory ( "/var/tmp" in my case ). If the file upload works, PHP obviously has permission to write to that temporary directory.
So - if *PHP* can write to the temporary directory - can I assume that a *PHP script* will also be able to write a that directory?
Is the answer the same on linux/unix as it is on windows?
Lindsay
Can a *PHP script* write to the temporary dir if *PHP* can?
Moderator: General Moderators
-
hellolindsay
- Forum Newbie
- Posts: 6
- Joined: Wed Jul 12, 2006 9:23 am
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
I believe Windows permissions are always 777 unless you change them. You can use chmod() in PHP I think, or change the permissions in your FTP client so that PHP (and any other script) can write to a folder.
-
hellolindsay
- Forum Newbie
- Posts: 6
- Joined: Wed Jul 12, 2006 9:23 am
I am developing an application that will be installed on many different servers. It has to work on a standard php installation - i don't want to have to chmod the tmp folder on every machine. So far, on every machine i've tried, PHP scripts can write to the temporary folder by default. I just want to be sure that this is always the case.
-
hellolindsay
- Forum Newbie
- Posts: 6
- Joined: Wed Jul 12, 2006 9:23 am
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Then don't use the temporary folder. Use a database. Files left in the temporary folder are not guaranteed to stick around for any length of time.hellolindsay wrote:tmpfile() is very intersting - i didn't know about that. Unfortunately i need to make a file that will remain after my script ends - so i can't use it.
Some hosts have a cron that clears the temporary directory very often.
-
hellolindsay
- Forum Newbie
- Posts: 6
- Joined: Wed Jul 12, 2006 9:23 am
Essentially, i am pre-uploading files before i know if the user wants to keep them. Ideally, the script should work without knowing anything about the application that is using it (ie. without knowing if a database is used, or if there is some pre-specified place where files can be written.) The files only have to persist for a few minutes - after that, if the user says they want to keep the file it gets moved somewhere permanent - if they don't, the file gets left in the temporary folder to be cleaned out when the server feels like it.