I'm probably missing something obvious, but I'm unable to write a file
with this function. I've used my FTP software to set permissions to
777 on all the files in question. I've tried r, r+, w, and w+ as
possible ways of opening the files.
The first fopen is trying to create a file where none exists. It fails
(thought I've set dir permissions to 777 as well). How can I create a
file?
There error messages print back the full input, so clearly the
variables are caputured and they have all the info that I expect to be
there. They just don't open the files.
The first attempt to create a file prints out my error message like
this:
"Error: in fileUpdate(), we tried to create a back up of your file and
give it the name backup_ppArrang ementsAdmin/createnewslette rsForm.php
, but we failed."
The second attempt to write to the existing file prints, in part, like
this:
"Error: in fileUpdate, something went wrong and we were unable to save
the document called ' ppArrangementsA dmin/createnewslette rsForm.php '.
You'd written:" - it then gives me everything I'd written.
Anyone see what I'm missing?
function fileUpdate() {
$controllerForA ll = & getController() ;
$updateObject = & $controllerForA ll->getObject("McT ransactions", " in
the function fileUpdate().") ;
$resultsObject = & $controllerForA ll->getObject("McR esults", " in the
function fileUpdate().") ;
$formInputs = $GLOBALS["formInputs "];
if (is_array($form Inputs)) {
extract($formIn puts);
$fileName = $fileName;
$fileContent = $fileContent;
$fileNameOld = $fileNameOld;
$fileContentOld = $fileContentOld ;
$fileNameBackup = "backup_".$file NameOld;
$fp = @fopen($fileNam eBackup, "w+");
$success = @fwrite($fp, $fileContentOld );
@fclose($fp);
if ($success) {
$resultsObject->addToResults(" We created a back up of your file and
gave it the name $fileNameBackup . If you need to restore the old
version, go back to that file.");
} else {
$resultsObject->addToResults(" Error: in fileUpdate(), we tried to
create a back up of your file and give it the name $fileNameBackup ,
but we failed.");
}
if (is_writable($f ilename)) {
$fp = @fopen($fileNam e, "r+");
$success = @fwrite($fp, $fileContent);
@fclose($fp);
}
if ($success) {
$resultsObject->addToResults(" We successfully saved the $fileName
document.");
} else {
$fileContent = htmlspecialchar s($fileContent) ;
$resultsObject->addToResults(" Error: in fileUpdate, something went
wrong and we were unable to save the document called ' $fileName '.
You'd written: $fileContent ");
}
} else {
$resultsObject->error("In fileUpdate, we assumed we were going to be
given a set of data called formInputs, but for some reason we got no
such thing.", "fileUpdate ");
}
}
with this function. I've used my FTP software to set permissions to
777 on all the files in question. I've tried r, r+, w, and w+ as
possible ways of opening the files.
The first fopen is trying to create a file where none exists. It fails
(thought I've set dir permissions to 777 as well). How can I create a
file?
There error messages print back the full input, so clearly the
variables are caputured and they have all the info that I expect to be
there. They just don't open the files.
The first attempt to create a file prints out my error message like
this:
"Error: in fileUpdate(), we tried to create a back up of your file and
give it the name backup_ppArrang ementsAdmin/createnewslette rsForm.php
, but we failed."
The second attempt to write to the existing file prints, in part, like
this:
"Error: in fileUpdate, something went wrong and we were unable to save
the document called ' ppArrangementsA dmin/createnewslette rsForm.php '.
You'd written:" - it then gives me everything I'd written.
Anyone see what I'm missing?
function fileUpdate() {
$controllerForA ll = & getController() ;
$updateObject = & $controllerForA ll->getObject("McT ransactions", " in
the function fileUpdate().") ;
$resultsObject = & $controllerForA ll->getObject("McR esults", " in the
function fileUpdate().") ;
$formInputs = $GLOBALS["formInputs "];
if (is_array($form Inputs)) {
extract($formIn puts);
$fileName = $fileName;
$fileContent = $fileContent;
$fileNameOld = $fileNameOld;
$fileContentOld = $fileContentOld ;
$fileNameBackup = "backup_".$file NameOld;
$fp = @fopen($fileNam eBackup, "w+");
$success = @fwrite($fp, $fileContentOld );
@fclose($fp);
if ($success) {
$resultsObject->addToResults(" We created a back up of your file and
gave it the name $fileNameBackup . If you need to restore the old
version, go back to that file.");
} else {
$resultsObject->addToResults(" Error: in fileUpdate(), we tried to
create a back up of your file and give it the name $fileNameBackup ,
but we failed.");
}
if (is_writable($f ilename)) {
$fp = @fopen($fileNam e, "r+");
$success = @fwrite($fp, $fileContent);
@fclose($fp);
}
if ($success) {
$resultsObject->addToResults(" We successfully saved the $fileName
document.");
} else {
$fileContent = htmlspecialchar s($fileContent) ;
$resultsObject->addToResults(" Error: in fileUpdate, something went
wrong and we were unable to save the document called ' $fileName '.
You'd written: $fileContent ");
}
} else {
$resultsObject->error("In fileUpdate, we assumed we were going to be
given a set of data called formInputs, but for some reason we got no
such thing.", "fileUpdate ");
}
}
Comment