Welcome Guest, Not a member yet? Register   Sign In
Message: mkdir(): Permission denied
#1

(This post was last modified: 09-29-2015, 03:29 PM by Lykos22.)

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 ?
Reply
#2

Have you tried making the folder writeable?..
Reply
#3

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.
Reply
#4

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

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

(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 ?
Reply
#7

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
Reply
#8

(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.
Reply
#9

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.
Reply
#10

(This post was last modified: 09-30-2015, 09:29 AM by jLinux.)

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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB