Hi Noob question but this is bugging me. I have recently tried using PHP in web pages, as an alternative to running Perl scripts in my cgi-bin, but I have difficulty getting past the "Hello World !" level because I don't seem to be able to use fopen() in 'a' mode to even make a simple, wee text file and write some $_POST data to it ! ! ! - Am I overlooking the glaringly obvious ? - All my Perl CGI scripts create and write text files quite happily. Is there a "missing ingredient" when I switch over to PHP ? - Thanks Chris
could be permissions, could be umask.... typically with fopen, you;d get a E_WARNING back though, like 'get lost, could not open the file for writing: permission denied' sort of thing. "If the open fails, the function an error of level E_WARNING is generated. You may use @ to suppress this warning. " make sure that at the start of your script you do error_reporting(E_ALL ^ E_NOTICE); (some php.ini hostings suppress it so as not to reveal to customers any errors that can be exploited) its useless wondering what is wrong until you see the errors
Thanks, lads. chmod 777 allowed the file create and subsequent writes, but isn't that a tad dangerous as regards security ? I've always avoided that like the plague. @ dimitar: you're right, my host server suppresses error reporting ! All I get back on echo is "2039". - I shall persevere. - Chris
well, in theory, yes. in practice, depends on your hosting. typically, it's sandboxed in 'safe mode' - which for php means that apache won't be able to access any file outside of your own directory structure. that being said, not all hosting setups are like so... in an ideal world - guid of any apache / php process spawned from your domain will be with the same privileges as your ftp user, hence being able to make directories and so forth. although that is also dangerous - dunno. a lot of hosting setups just leave it to apache:apache. What i tend to do (if i got root) is chown my output directory to that and not worry too much about permissions. check the ownership of the files that it created to find how it runs... anyway, i wouldn't worry about it too much.