File Permissions

How to write into file

Page 1 of 1

4 Replies - 1713 Views - Last Post: 10 May 2006 - 12:57 AM Rate Topic: -----

#1 david4u  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 38
  • Joined: 26-April 06

File Permissions

Posted 01 May 2006 - 01:01 AM

I am using windows and I have a csv file that I need to open via link, but when I click on the link, it give this error below. I have checked the permission on the file,it seems alright. What else can I do to correct this error:

Warning: fopen(result.csv) [function.fopen]: failed to open stream: Permission denied in C:\wamp\www\WEB\HEAVEN\websurvey\admin\csv_result.php on line 29

Line 29 is:

// open the result file for write
$csv_file = ("result.csv");
$fp = fopen($csv_file , "w");

Can anyone help.

Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: File Permissions

#2 ktsirig  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 94
  • Joined: 14-September 05

Re: File Permissions

Posted 09 May 2006 - 03:20 PM

Sometimes it is solved if you state tha full path to file you want to open. Mind the '/', which must be '\' in Windows systems.
Also, a problem occurs if the server user doesn't have permission to do things, such as write to files.
Was This Post Helpful? 0
  • +
  • -

#3 William_Wilson  Icon User is offline

  • lost in compilation
  • member icon

Reputation: 205
  • View blog
  • Posts: 4,807
  • Joined: 23-December 05

Re: File Permissions

Posted 09 May 2006 - 10:01 PM

Since it is a comment, the '\' should be fine, but you may want to be sure you are using the correct file, as if the file is not already there, it will not create it,
you would need 'a+' for that.
The same error can occur if the server does not have any space, the file would be writable, but the writting could not actuallt occur.
to open a file, you are doing it correctly, but i would suggest the following to determine the problem's source:
if (is_writable($csv_file)) {
     echo "$csv_file is writable <br />";
     if (!$fp = fopen($csv_file, 'a')) {
         echo "Cannot open file ($csv_file)";
         exit;
   }
   if (fwrite($fp, $content) === FALSE) {
       echo "Cannot write to file ($csv_file)";
       exit;
   }
}
else{
     echo "$csv_file is not writable <br />";
}


be sure you are including an extension in your $csv_file as well.
Also you can try placing quotes around $csv_file ("$csv_file"), this may help as well.
*There is also a php/javascript bug in the windows IE beta1, most codes seem to generate errors with that version, that do not occur in FF or in the beta 2.
Was This Post Helpful? 0
  • +
  • -

#4 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 84
  • View blog
  • Posts: 3,564
  • Joined: 31-March 03

Re: File Permissions

Posted 09 May 2006 - 11:33 PM

ktsirig, on 9 May, 2006 - 03:12 PM, said:

Mind the '/', which must be '\' in Windows systems.

That's actually untrue, Windows can use either. You'll just need to remember to escape \.

That is to say...
$file1 = "C:\profiles\nexus\rewritten_paper.txt";
$file2 = 'C:\profiles\nexus\rewritten_paper.txt';
var_dump($file1);
var_dump($file2);


...aren't the same. The first is parsed so that \n and \r as newline and return carriage characters. The second is parsed as a simple string and everything is left AS IS.

The first ($file1) you would need to escape, add a another \ before the \, so that \r and \n wouldn't be parsed as newline and return carriage.
Was This Post Helpful? 0
  • +
  • -

#5 david4u  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 38
  • Joined: 26-April 06

Re: File Permissions

Posted 10 May 2006 - 12:57 AM

Thanks alot, I will implement it and let you guys know what happened.

Cheers.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1