CodeIgniter Forums
error "failed to open stream: Permission denied" when creating a php text file - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: error "failed to open stream: Permission denied" when creating a php text file (/showthread.php?tid=49840)



error "failed to open stream: Permission denied" when creating a php text file - El Forum - 03-05-2012

[eluser]SidharthaXx[/eluser]
Hi All,

I'm trying to create an attachment file in my controller, very simple test code as below,

function create_vcal() {

$ourFileName = "/home/robbiedb/Downloads/bobber.ics";
echo "got here";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
$stringData = "Bobby Bopper\n";
fwrite($ourFileHandle, $stringData);
fclose($ourFileHandle);

}

Anyway, I'm getting an error "failed to open stream: Permission denied". This suprises me, since I'm trying to access my local hard drive under my user "robbiedb"...

Anyone know why I might be getting this error?

Thanks


error "failed to open stream: Permission denied" when creating a php text file - El Forum - 03-05-2012

[eluser]Mario "St.Peter" Valentino[/eluser]
i think you should chmod the folder
chmod -R 777 folder_name or file


error "failed to open stream: Permission denied" when creating a php text file - El Forum - 03-05-2012

[eluser]InsiteFX[/eluser]
You do not want to chmod to 777

This is what you want to do and you can do it with PHP
Code:
// Read and write for owner, read for everybody else
chmod("/somedir/somefile", 0644);

PHP.NET
CHMOD