MadnessRed Posted June 21, 2008 Share Posted June 21, 2008 ok I have a file called "write.php", I want it to create a file called $_get['directory'].'/'.$_get['name'].'.txt' and then make it so it is chmod 777 how would i go abuot that? thanks Link to comment https://forums.phpfreaks.com/topic/111273-create-a-file-which-is-chmod-777/ Share on other sites More sharing options...
DarkWater Posted June 21, 2008 Share Posted June 21, 2008 By reading the manual? =/ Do you want anything inside the file, or do you just want it created? For the former, use file_put_contents();. For the later use touch(). Then use chmod(). Link to comment https://forums.phpfreaks.com/topic/111273-create-a-file-which-is-chmod-777/#findComment-571174 Share on other sites More sharing options...
MadnessRed Posted June 21, 2008 Author Share Posted June 21, 2008 I will want to write to it, but later, for now i just want a text file created which I can name and choose the directory of. I tried using fopen but it jsut said the the fiels didn't exist even though fopen should create it. Link to comment https://forums.phpfreaks.com/topic/111273-create-a-file-which-is-chmod-777/#findComment-571190 Share on other sites More sharing options...
DarkWater Posted June 21, 2008 Share Posted June 21, 2008 I said to use touch(). =P Link to comment https://forums.phpfreaks.com/topic/111273-create-a-file-which-is-chmod-777/#findComment-571192 Share on other sites More sharing options...
MadnessRed Posted June 21, 2008 Author Share Posted June 21, 2008 The touch() function sets the access and modification time of the specified file. how does that help me? how about this code though? //First set the file path $file = $_get['directory'].'/'.$_get['name'].'.txt'; //now the option to put in some content, blank atm $content = ""; //Now we don't want to damage an existing files if (file_exists($file)) { echo 'Error, file already exists'; }else{ //Create the file file_put_contents($file,$content); //Make it writeable chmod($file,0777); //Success, lets tell them echo 'File made successfully'; } Link to comment https://forums.phpfreaks.com/topic/111273-create-a-file-which-is-chmod-777/#findComment-571199 Share on other sites More sharing options...
DarkWater Posted June 21, 2008 Share Posted June 21, 2008 If you've ever used Unix, you'd know it creates the file if it doesn't exist. Link to comment https://forums.phpfreaks.com/topic/111273-create-a-file-which-is-chmod-777/#findComment-571210 Share on other sites More sharing options...
MadnessRed Posted June 22, 2008 Author Share Posted June 22, 2008 yh but i use unix through gnome, not php how about this code then? //First set the file path $file = $_get['directory'].'/'.$_get['name'].'.txt'; //now the option to put in some content, blank atm $content = ""; //Now we don't want to damage an existing files if (file_exists($file)) { echo 'Error, file already exists'; }else{ //Create the file touch($file); //Make it writeable chmod($file,0777); //Add contents is I decide to make them file_put_contents($file,$content); //Success, lets tell them echo 'File made successfully'; } Link to comment https://forums.phpfreaks.com/topic/111273-create-a-file-which-is-chmod-777/#findComment-571390 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.