Jump to content

CHMOD a file to 777


Juniorflip

Recommended Posts

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.