open file in linux box

#1
[eluser]Sub-Zero[/eluser]
Hi!

I wrote this script before in Windows and it works perfect. Now, my office decided to migrate everything into a redhat box running apache. I changed the windows path to the linux path and I'm getting an error msg. Any suggestions? BTW, the folder is set up with the following permissions: 755.

Here is a sample code:
$logfileHeader ='<DOCTYPE html PUBLIC...';

$logfile = "visitor.html";
$dir = "/usr/local/apache/htdocs/sample1/system/logger";
$location = $dir.'/'.$logfile;

if(!file_exists($location)){
$logfile = fopen("$location", "w") or die('Cannot write to file');
fwrite($logfile, $logfileHeader);
}
else{
$logfile = fopen($savelocation, "a");
}
fwrite($logfile, $logEntry);
fclose($logfile);

#2
[eluser]BrianDHall[/eluser]
It would be helpful to know the error message, and where things start going wrong - for instance, does the file_exists() call return true or false?

Its highly advisable when such a problem is encountered to slowly go through to narrow down when things go wrong, as if often gives you the answer all by itself.

#3
[eluser]Sub-Zero[/eluser]
A PHP Error was encontered

Severity Warning

Message fopen(/usr/local/apache/htdocs/sample1/system/logger/visitor.html)[function fopen]: failed to open stream: No such file or directory.

#4
[eluser]n0xie[/eluser]
Check the file permissions on visitor.html

#5
[eluser]BrianDHall[/eluser]
OK, first of all you'll need to figure out exactly which call is creating the problem - 0755 will only permit writing by Owner, so if your server/php isn't the owner of the file it won't be able to open the file for writing.

Does the file exist according to file_exists()? If not, something is wrong with $location. If it does exist, what fopen call precisely is causing the error? I notice you have or die() on one of them but your die isn't being called, so I presume it is one of the other ones.

For debugging as a quick check, make the directory and file permission 0777.

There is nothing wrong with doing things with fopen or the like, but as an entirely different suggestion you might take a look at the file helper provided by CI.

That doesn't mean you can't use fopen, I just personally have found the file helper easier to use for common tasks.

#6
[eluser]Sub-Zero[/eluser]
Hi! I have changed all the directories to 777... still the same problem... Also, the script should be creating an html file by itself. If the file exits then the file will be appended... I was wondering if i has something to do with the slashes...


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.