Jump to content


Photo

CHMOD a file to 777


  • Please log in to reply
4 replies to this topic

#1 Juniorflip

Juniorflip
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 18 October 2006 - 02:59 PM

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?

#2 xsist10

xsist10
  • Members
  • PipPipPip
  • Advanced Member
  • 114 posts

Posted 18 October 2006 - 03:02 PM

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.
SA PHP Archives - www.phparchives.za.org

#3 Juniorflip

Juniorflip
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 18 October 2006 - 03:33 PM

because I am trying to join the file to two other file to make an xml here is my source

<?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();


?>


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

#4 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 18 October 2006 - 03:38 PM

Funnily enough php has a function called chmod.

#5 Juniorflip

Juniorflip
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 18 October 2006 - 04:12 PM

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 php

When I use this code it doesn't bring over the XXXXbody.xml
$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();

However if I manual type it in it works!!!  any help would be appreciated
<?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();


?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users