File Permission and Usage

I am getting "failed to open stream: Permission denied in....line 32" why?
How can I stop "failed to open stream" exception?

Explanation

Each file will have its own properties.
It can be a 'read only' file or a file that cannot even be read.
The permission for each file can be modified. There are basically three levels "read/write/execute".
If we are doing a write operation in a file, proper write permission should be given to that file.
Example:
In the below example we show the permission denied issue. Here we try to write in to a file called "test5.txt", which does not have write permission.
<?php
$file1 = "./test5.txt";
$open = fopen($file1, "w");
fwrite($open,"test"); ?>
As a result we get the permission denied exception.

Warning: fopen(./test5.txt) [function.fopen]: failed to open stream: Permission denied in /opt/lampp/htdocs/hscripts/site/tutorials/php/file-functions/file-permission.php on line 57
Warning: fopen(./test5.txt) [function.fopen]: failed to open stream: Permission denied in /opt/lampp/htdocs/hscripts/site/tutorials/php/file-functions/file-permission.php on line 58

How to set Permission / stop permission denied:
The permission can be set using the filemanager / ftp tools.
Upload the file. Go to filemanager/ ftp tool, select the file and change the permission to required value.

PHP Topics


Ask Questions

Ask Question