469,588 Members | 2,741 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,588 developers. It's quick & easy.

fopen php5 htaccess question

Hello,
Im doing this in php5, apache
Im not sure where the problem lies but I have a file
<?php
Class CreateXML{
public function xmlDeclaration(){
return $varxmlDec = "<?xml version='1.0'> ";
}
public function rssDeclaration(){
return $varrssDec = "<rss version='2.0'>";
}
}

?>
THAT IS CALLED BY:

<?php
include "XmlClass.php";

$test = new CreateXML();
$varxmlDec = $test->xmlDeclaration();
$varrssDec = $test->rssDeclaration();

$data = $test->varxmlDec.$test->varrssDec;
$file = "newfile.xml";
if (!$file_handle = fopen($file,"a")) { echo "Cannot open file"; }
if (!fwrite($file_handle, $data)) { echo "Cannot write to file"; }
echo "You have successfully written data to $file";
fclose($file_handle);
?>

THIS DOES NOT WORK.
It may have something to do with a .htaccess file.(But I dont think so)
If I use: AddHandler application/x-httpd-php4 .php .php4 .php3 .phtml
..htm .html
I get a dalog box that asks me if I want to open/download
writetestxml.php (which is the file I'm accessing)
I tried using ......-httpd-php5 but the same thing happens.

Help!
Thanks
Mike
Nov 22 '05 #1
2 3439
Actually, now i just get:
Warning: fopen(newfile.xml) [function.fopen]: failed to open stream:
Permission denied in /home/ampsof00/public_html/XML/writexmltest.php on line
12
Cannot open file
Warning: fwrite(): supplied argument is not a valid stream resource in
/home/ampsof00/public_html/XML/writexmltest.php on line 13
Cannot write to fileYou have successfully written data to newfile.xml
Warning: fclose(): supplied argument is not a valid stream resource in
/home/ampsof00/public_html/XML/writexmltest.php on line 15

My permissions are 755.
"Mike" <am******@verizon.net> wrote in message
news:MRuef.35701$Vb.12829@trndny05...
Hello,
Im doing this in php5, apache
Im not sure where the problem lies but I have a file
<?php
Class CreateXML{
public function xmlDeclaration(){
return $varxmlDec = "<?xml version='1.0'> ";
}
public function rssDeclaration(){
return $varrssDec = "<rss version='2.0'>";
}
}

?>
THAT IS CALLED BY:

<?php
include "XmlClass.php";

$test = new CreateXML();
$varxmlDec = $test->xmlDeclaration();
$varrssDec = $test->rssDeclaration();

$data = $test->varxmlDec.$test->varrssDec;
$file = "newfile.xml";
if (!$file_handle = fopen($file,"a")) { echo "Cannot open file"; }
if (!fwrite($file_handle, $data)) { echo "Cannot write to file"; }
echo "You have successfully written data to $file";
fclose($file_handle);
?>

THIS DOES NOT WORK.
It may have something to do with a .htaccess file.(But I dont think so)
If I use: AddHandler application/x-httpd-php4 .php .php4 .php3 .phtml
.htm .html
I get a dalog box that asks me if I want to open/download
writetestxml.php (which is the file I'm accessing)
I tried using ......-httpd-php5 but the same thing happens.

Help!
Thanks
Mike

Nov 22 '05 #2
Mike wrote:
Actually, now i just get:
Warning: fopen(newfile.xml) [function.fopen]: failed to open stream:
Permission denied in /home/ampsof00/public_html/XML/writexmltest.php
on line
12
Cannot open file
Warning: fwrite(): supplied argument is not a valid stream resource in
/home/ampsof00/public_html/XML/writexmltest.php on line 13
Cannot write to fileYou have successfully written data to newfile.xml
Warning: fclose(): supplied argument is not a valid stream resource in
/home/ampsof00/public_html/XML/writexmltest.php on line 15

My permissions are 755.


Isolate your problem! Take all the XML junk out! That's not your
problem. Your problem is with fopen. You are trying to open newfile.xml
for append access and you can't. While you check your error and issue
an error message you blindly go onward as if it's OK. It's not OK. The
file open failed!

Your permissions of 755 I suspect is on writexmltest.php not on
newfile.xml! That's not the issue. Apache opened writexmltest.php and
was executing it already. The fopen failed.

Realize that Apache runs as a pretty plain, unprivileged user (something
like "apache" or "www"). Thus if newfile.xml exists, the user "apache"
(or "www" or whatever your Apache server runs as) needs to have write
access to that file (i.e other write needs to be turned on - e.g. 777).
Also, if newfile.xml does not exist then the parent directory needs to
allow "apache" (or "www") to be able to create files in that directory
(i.e. 777 on the parent directory). You should probably pick another,
more innocuous path in your file system for this (for example, get this
working with $file = "/tmp/newfile.xml" first).
Nov 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Nicko | last post: by
4 posts views Thread by Chuck Anderson | last post: by
4 posts views Thread by awebguynow | last post: by
19 posts views Thread by McKirahan | last post: by
3 posts views Thread by IamtheEvster | last post: by
2 posts views Thread by Giorgio Sam | last post: by
reply views Thread by botho.willer | last post: by
20 posts views Thread by cscorley | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.