CodeIgniter Forums
Message: mkdir(): Permission denied - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Message: mkdir(): Permission denied (/showthread.php?tid=63136)

Pages: 1 2 3


Message: mkdir(): Permission denied - Lykos22 - 09-29-2015

I have this PHP script inside my Post_model constructor:

PHP Code:
$dir FCPATH 'uploads' DIRECTORY_SEPARATOR 'posts'
if (!
is_dir($dir)) {
    
mkdir($dir755true);


which shows me this error:
Code:
Severity: Warning

Message: mkdir(): Permission denied

and can't create the posts folder in order to upload images. If I comment this code and create the uploads/posts folder manually and then try to upload a file, the upload library shows my an error saying that the folder is not writable. How can I fix this error ?


RE: Message: mkdir(): Permission denied - jLinux - 09-29-2015

Have you tried making the folder writeable?..


RE: Message: mkdir(): Permission denied - Lykos22 - 09-30-2015

jLinuxHave you tried making the folder writeable?..

Hi, I have tried using
Code:
mkdir($dir, 0777, true);

but also didn't work. I have also tried using relative paths too, like:


Code:
$dir = 'uploads' . DIRECTORY_SEPARATOR . 'posts';

or

$dir = './uploads/posts';

but no luck at all.

The thing is that I'm on a project where many users can log in (think of a blog) and can upload images and create album folders inside the upload folder, so every member sould be able to do that.


RE: Message: mkdir(): Permission denied - Muzikant - 09-30-2015

The question is, is your directory (within you want to create a new directory) writable?


RE: Message: mkdir(): Permission denied - Martin7483 - 09-30-2015

Not only if it is writable, but does the owner of the script have the correct permissions to write in the root directory?


RE: Message: mkdir(): Permission denied - Lykos22 - 09-30-2015

(09-30-2015, 02:42 AM)Martin7483 Wrote: Not only if it is writable, but does the owner of the script have the correct permissions to write in the root directory?

How can I check this ? and if not how can I fix this ?


RE: Message: mkdir(): Permission denied - Martin7483 - 09-30-2015

You can use the PHP function is_writable( $filename )
http://php.net/manual/en/function.is-writable.php
It should check if the current user may write to the passed filename, where filename may be a file or directory.

But if I was you, I would create a directory manually in your root directory and set the read/write permissions. Then use this directory as your base dir for the uploads. As this directory seems to be required for your application there is no need to set it via a PHP script


RE: Message: mkdir(): Permission denied - Lykos22 - 09-30-2015

(09-30-2015, 03:56 AM)Martin7483 Wrote: You can use the PHP function is_writable( $filename )
http://php.net/manual/en/function.is-writable.php
It should check if the current user may write to the passed filename, where filename may be a file or directory.

But if I was you, I would create a directory manually in your root directory and set the read/write permissions. Then use this directory as your base dir for the uploads. As this directory seems to be required for your application there is no need to set it via a PHP script

I have also tried to to comment out this script and create the folder manually as you said with permissions 0777, although is not so secure, but when I tried to upload a file the Upload library was displaying a message that the folder was not writable (!!!).

Also the uploads folder is my base dir for storing everything that a user uploads, like posts (posts dir is the base dir for all post images). In my uploads dir I'm also planning to store images for photo albums, so imagine that each user should have the ability to create album folders for uploading their photos in them.

So basically some sub-folders in the uploads directory would have to create them with PHP.

One additional thing I tried is to upload an image straight in my uploads directory, but I was still getting the same error.


RE: Message: mkdir(): Permission denied - Martin7483 - 09-30-2015

If you set permissions to 0777 and still get the error, then the directory does not have 0777 permissions. If the original permissions were set to 0600 then only the super user can change the permissions of the directory. And it sounds like this is the case.


RE: Message: mkdir(): Permission denied - jLinux - 09-30-2015

Code:
man chmod
Code:
chmod -R 755 /path/to/folder
or if you're SURE this is ok..
Code:
chmod -R 777 /path/to/folder