473,394 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

no matter how I set permissions, I'm unable to write a file

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_ppArrangementsAdmin/createnewslettersForm.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 ' ppArrangementsAdmin/createnewslettersForm.php '.
You'd written:" - it then gives me everything I'd written.

Anyone see what I'm missing?


function fileUpdate() {
$controllerForAll = & getController();
$updateObject = & $controllerForAll->getObject("McTransactions", " in
the function fileUpdate().");
$resultsObject = & $controllerForAll->getObject("McResults", " in the
function fileUpdate().");

$formInputs = $GLOBALS["formInputs"];

if (is_array($formInputs)) {
extract($formInputs);

$fileName = $fileName;
$fileContent = $fileContent;
$fileNameOld = $fileNameOld;
$fileContentOld = $fileContentOld;

$fileNameBackup = "backup_".$fileNameOld;
$fp = @fopen($fileNameBackup, "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($filename)) {
$fp = @fopen($fileName, "r+");
$success = @fwrite($fp, $fileContent);
@fclose($fp);
}

if ($success) {
$resultsObject->addToResults("We successfully saved the $fileName
document.");
} else {
$fileContent = htmlspecialchars($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");
}
}
Jul 17 '05 #1
2 2301
lawrence wrote:
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_ppArrangementsAdmin/createnewslettersForm.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 ' ppArrangementsAdmin/createnewslettersForm.php '.
You'd written:" - it then gives me everything I'd written.

Anyone see what I'm missing?


function fileUpdate() {
$controllerForAll = & getController();
$updateObject = & $controllerForAll->getObject("McTransactions", " in
the function fileUpdate().");
$resultsObject = & $controllerForAll->getObject("McResults", " in the
function fileUpdate().");

$formInputs = $GLOBALS["formInputs"];

if (is_array($formInputs)) {
extract($formInputs);

$fileName = $fileName;
$fileContent = $fileContent;
$fileNameOld = $fileNameOld;
$fileContentOld = $fileContentOld;

$fileNameBackup = "backup_".$fileNameOld;
$fp = @fopen($fileNameBackup, "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($filename)) {
$fp = @fopen($fileName, "r+");
$success = @fwrite($fp, $fileContent);
@fclose($fp);
}

if ($success) {
$resultsObject->addToResults("We successfully saved the $fileName
document.");
} else {
$fileContent = htmlspecialchars($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");
}
}


Haven't reviewed your code, but out of experience, what about permissions to
the folder in question ?

--
Peace and long life ...
Registeret Linux user #292411
Jul 17 '05 #2
lawrence wrote:
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.
Possibly need to use absolute paths so the server knows exactly where
the directory structure is. I always use a base path so files other than
in the directory I want are being overwritten.

<snip>
function fileUpdate() {
$controllerForAll = & getController();
$updateObject = & $controllerForAll->getObject("McTransactions", " in
the function fileUpdate().");
$resultsObject = & $controllerForAll->getObject("McResults", " in the
function fileUpdate().");

$formInputs = $GLOBALS["formInputs"];

if (is_array($formInputs)) {
extract($formInputs);

$fileName = $fileName;
I'd suggest trying something more like:

$fileName= dirname(__FILE__).str_replace('../','',$fileName);

Where the directories you want to write into are located at the same
level as the file that contains this function declaration.

For instnace:

thisfile.php
writable_dir1/
writable_dir2/
etc...
$fileContent = $fileContent;
$fileNameOld = $fileNameOld;
$fileContentOld = $fileContentOld;

$fileNameBackup = "backup_".$fileNameOld;


Same thing here. Use an absolute base path. This will _help_ with
preventing some bad holes from appearing, but the biggest thing to
remember: *DON'T* *TRUST* *USER* *INPUT* - even if it is from a posted form.

<snip>

--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.
SEO Competition League: http://seo.koivi.com/
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: lkrubner | last post by:
I want to give users the power to edit files from an easy interface, so I create a form and a PHP script called "fileUpdate". It does a reasonable about of error checking and prints out some...
0
by: Fran Tirimo | last post by:
I am developing a small website using ASP scripts to format data retrieved from an Access database. It will run on a Windows 2003 server supporting FrontPage extensions 2002 hosted by the company...
2
by: Fran Tirimo | last post by:
I am developing a small website using ASP scripts to format data retrieved from an Access database. It will run on a Windows 2003 server supporting FrontPage extensions 2002 hosted by the company...
9
by: Ben Dewey | last post by:
Project: ---------------------------- I am creating a HTTPS File Transfer App using ASP.NET and C#. I am utilizing ActiveDirectory and windows security to manage the permissions. Why reinvent...
6
by: Alvin Bruney [MVP] | last post by:
Hi group, its been a while... I encountered a nasty permissions error that I was unable to solve and eventually had a workaround but it has been at the back of my mind for a while. Any takers? ...
2
by: Brian Cooper | last post by:
I am trying to determine a permission problem trying to write a text file from one web server to another. Here is the situation: We have two domains in place one is Active Directory and the...
0
by: Phil Latio | last post by:
OT as this question relates to MSQuery, which maybe the people here could answer - they often know alot more than just Access :) I have a few Excel spreadsheets set up which use MSQuery to...
3
by: bizt | last post by:
Hi, I am trying to carry out an upload and save file in directory operation using move_uploaded_file(). However, when I run the script it give me the following error: Warning:...
3
by: eholz1 | last post by:
Hello PHP Group, I am having trouble setting permissions correctly so that the magickwand api (php 5.2) can read and write images. I usually read a file from one directory, create a magickwand...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.