Jump to content

Archived

This topic is now archived and is closed to further replies.

Juniorflip

CHMOD a file to 777

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Funnily enough php has a function called [url=http://php.net/chmod]chmod[/url].

Share this post


Link to post
Share on other sites
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
[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]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.