On Mon, Mar 28, 2011 at 11:43 PM, Ethan Rosenberg <ethros@xxxxxxxxxxxxx>wrote:
> At 11:14 PM 3/28/2011, Adam Richardson wrote:
>
>> On Mon, Mar 28, 2011 at 11:03 PM, Ethan Rosenberg <<mailto:
>> ethros@xxxxxxxxxxxxx>ethros@xxxxxxxxxxxxx> wrote:
>> At 01:32 AM 3/28/2011, Hans Ãïhlin wrote:
>> Do you have SELinux installed?
>>
>> 2011/3/28 Ethan Rosenberg <<mailto:ethros@xxxxxxxxxxxxx>
>> ethros@xxxxxxxxxxxxx>:
>>
>> > Dear List -
>> >
>> > Thanks for all your help in the past. Ã Here is another one...
>> >
>> > I am getting a Permission Denied" message when I try to run a PHP
>> script. Ã I
>> > just changed the mode on the directory and the files to 777. Ã This
>> problem
>> > arose when I changed the permissions. Ã I thought I was solving a
>> problem,
>> > because I could not open a file for writing. Ã I was not receiving error
>> > messages, but no file was created.
>> >
>> > Help and advice, please.
>> >
>> > Ethan Rosenberg
>> >
>> >
>> >
>> **********************************************
>> Ã Hans Ãïhlin
>> Ã Ã Tel: +46761488019
>> Ã Ã icq: 275232967
>> Ã Ã <http://www.kronan-net.com/>http://www.kronan-net.com/
>> Ã Ã irc://<http://irc.freenode.net:6667>irc.freenode.net:6667 - TheCoin
>>
>> **********************************************
>>
>>
>> Hans -
>>
>> Sorry, I did not include my signature, which includes all the requested
>> information.
>>
>> Here it is....
>>
>> Ethan
>> ==========
>> MySQL 5.1 PHP 5.3.3-6 Linux [Debian (sid)]
>>
>>
>> The problem persists. I cannot write to a file from PHP.
>>
>> Any more suggestions?
>>
>> Thanks.
>>
>> Ethan
>>
>>
>> Hi Ethan,
>>
>> Are you using suPHP or suExec? I believe the server chokes on 777
>> permissions in those cases.
>>
>> Have you checked the permissions in the command line (sorry for the basic
>> question, but just making sure I know what you've already done?)
>>
>> Also, can we see some of the code you're using to handle the file
>> processing?
>>
>> Thanks,
>>
>> Adam
>>
>> --
>> Nephtali: A simple, flexible, fast, and security-focused PHP framework
>> <http://nephtaliproject.com>http://nephtaliproject.com
>>
>
> +++++++++
>
> Adam -
>
> Thanks.
>
> 1] Pardon my ignorance but I do not understand this - Are you using suPHP
>> or suExec?
>>
>
suPHP and suExec are two modules that allow PHP to run with the permissions
of the user, making it easy to write files to disk. However, suPHP (and I
believe suExec, but I can't remember for sure) does not like 777
permissions.
>
> 2] I changed the permissions to 755 and the "Permission Denied" message
> went away.
>
Check!
>
> 3] Have you checked the permissions in the command line? Yes
>
Check!
>
> 4] Here are some code snippets:
>
> $fptr1 = fopen("chessboard", "r+"); //this works
> $fptr2 = fopen('chessboard', 'w'); //this deletes the file, as it should
> for($i = 0; $i <8; $i++)
> {
> for ($j = 0; $j < 8; $j++)
> fprinf($fptr2, "%s ", $results[$i][$j]);
> fprinf($fptr2, "\n");
>
> } //this never writes, so I am left with an empty file
Can you try a simplified form that checks for success along the way? How
about something like the code below to see how far it gets (I haven't
tested, but it should be close):
<?php
// let's make sure you see the E_WARNING errors if present for file
functions
error_reporting(-1);
// set var for later
$cost = 120.89;
if (!($fp = fopen("test.txt", 'w'))) {
echo "Can't open or create file!";
} else if (!($len = fprintf($fp, "In the year 3000, a Coke will cost %01.2f,
with tax.", $cost))) {
echo "Can't write to file!";
} else if (!(fclose($fp))) {
echo "Can't properly close file!";
}
?>
What do you see if you run this?
Adam
--
Nephtali: A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com