Juniorflip Posted October 18, 2006 Share Posted October 18, 2006 Is there a function that can make a file 777. I am trying to create a file and then make it chmod to 777 so I can join it with another file? Link to comment https://forums.phpfreaks.com/topic/24344-chmod-a-file-to-777/ Share on other sites More sharing options...
xsist10 Posted October 18, 2006 Share Posted October 18, 2006 Why do you want to chmod it to 777. If you can create it through using PHP then you can edit and delete it. You won't need to chmod it. Link to comment https://forums.phpfreaks.com/topic/24344-chmod-a-file-to-777/#findComment-110727 Share on other sites More sharing options...
Juniorflip Posted October 18, 2006 Author Share Posted October 18, 2006 because I am trying to join the file to two other file to make an xml here is my source[code]<?php/******START CODE EXTRACT******/if(!function_exists("file_get_contents")){ function file_get_contents($f = null) { if(is_null($f)) return null; return implode("", file($f)); }}/*******END CODE EXTRACT*******/$ourFileName = $campaign."body.xml";if (file_exists($ourFileName)) { $fh = fopen($ourFileName, 'a');} else { $fh = fopen($ourFileName, 'w') or die("can't open file");}$record = "<record>";$campaignid = "<campaignid>";$experienceid = "<experience>";$noteid = "<note>";$nameid = "<name>";$record2 = "</record>";$campaignid2 = "</campaignid>";$experienceid2 = "</experience>";$noteid2 = "</note>";$nameid2 = "</name>";fwrite($fh, $record);fwrite($fh, "\n");fwrite($fh, "\n");fwrite($fh, $campaignid);fwrite($fh, $campaign);fwrite($fh, $campaignid2);fwrite($fh, "\n");fwrite($fh, "\n");fwrite($fh, $experienceid);fwrite($fh, $experience);fwrite($fh, $experienceid2);fwrite($fh, "\n");fwrite($fh, "\n");fwrite($fh, $noteid);fwrite($fh, $note);fwrite($fh, $noteid2);fwrite($fh, "\n");fwrite($fh, "\n");fwrite($fh, $nameid);fwrite($fh, $name);fwrite($fh, $nameid2);fwrite($fh, "\n");fwrite($fh, "\n");fwrite($fh, $record2);fclose($fh);$ourFileName2 = $ourFileName;Function create_xml() {$files = array('header.xml',$ourFileName2,'footer.xml');foreach($files as $file){ $contents[] = file_get_contents($file);}$fp = fopen('new_file.xml','w+');fwrite($fp,join("\n",$contents));fclose($fp);}create_xml();?>[/code]It will create XXXXbody.xml and it will create new_file.xml. new_file.xml will have header and footer in it. but it will not have body.xml in it. I am wondering if because it can not access the file Link to comment https://forums.phpfreaks.com/topic/24344-chmod-a-file-to-777/#findComment-110745 Share on other sites More sharing options...
trq Posted October 18, 2006 Share Posted October 18, 2006 Funnily enough php has a function called [url=http://php.net/chmod]chmod[/url]. Link to comment https://forums.phpfreaks.com/topic/24344-chmod-a-file-to-777/#findComment-110751 Share on other sites More sharing options...
Juniorflip Posted October 18, 2006 Author Share Posted October 18, 2006 Ok I am on the last part YAY!!! I just can't figure this last one out. if I put in the array the actual body name it work however if I put in a variable it doesn't here is the excerpt and the full phpWhen I use this code it doesn't bring over the XXXXbody.xml[code]$ourFileName2 = $ourFileName;Function chmod_xml() {chmod('1610body.xml', 0777); // octal; correct value of mode}chmod_xml();Function create_xml() {$files = array('header.xml',$ourFileName2,'footer.xml');foreach($files as $file){ $contents[] = file_get_contents($file);}$fp = fopen('new_file.xml','w+');fwrite($fp,join("\n",$contents));fclose($fp);}create_xml();[/code]However if I manual type it in it works!!! any help would be appreciated[code]<?php/******START CODE EXTRACT******/if(!function_exists("file_get_contents")){ function file_get_contents($f = null) { if(is_null($f)) return null; return implode("", file($f)); }}/*******END CODE EXTRACT*******/$ourFileName = $campaign."body.xml";if (file_exists($ourFileName)) { $fh = fopen($ourFileName, 'a');} else { $fh = fopen($ourFileName, 'w') or die("can't open file");}$record = "<record>";$campaignid = "<campaignid>";$experienceid = "<experience>";$noteid = "<note>";$nameid = "<name>";$record2 = "</record>";$campaignid2 = "</campaignid>";$experienceid2 = "</experience>";$noteid2 = "</note>";$nameid2 = "</name>";fwrite($fh, $record);fwrite($fh, "\n");fwrite($fh, "\n");fwrite($fh, $campaignid);fwrite($fh, $campaign);fwrite($fh, $campaignid2);fwrite($fh, "\n");fwrite($fh, "\n");fwrite($fh, $experienceid);fwrite($fh, $experience);fwrite($fh, $experienceid2);fwrite($fh, "\n");fwrite($fh, "\n");fwrite($fh, $noteid);fwrite($fh, $note);fwrite($fh, $noteid2);fwrite($fh, "\n");fwrite($fh, "\n");fwrite($fh, $nameid);fwrite($fh, $name);fwrite($fh, $nameid2);fwrite($fh, "\n");fwrite($fh, "\n");fwrite($fh, $record2);fclose($fh);$ourFileName2 = $ourFileName;Function chmod_xml() {chmod('1610body.xml', 0777); // octal; correct value of mode}chmod_xml();Function create_xml() {$files = array('header.xml','1610body.xml','footer.xml');foreach($files as $file){ $contents[] = file_get_contents($file);}$fp = fopen('new_file.xml','w+');fwrite($fp,join("\n",$contents));fclose($fp);}create_xml();?>[/code] Link to comment https://forums.phpfreaks.com/topic/24344-chmod-a-file-to-777/#findComment-110766 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.