Warning: mkdir(): Permission denied in

Hello,

[php]if(!file_exists(BACKUPDIR)){
if (!mkdir(BACKUPDIR, 0700, true)) {
die(‘Failed to create folders…’);
}
}[/php]

The above code gives the following error

Warning: mkdir(): Permission denied in /www/htdocs/modules_v3/simple_db_backup/admin_db_backup.php on line 245 Failed to create folders...

I wonder what is the problem?

Thank you in advance

The user your web server is running as doesn’t have permission to create that folder.

Thank you for your answer.

Do you have one solution?

Thanks

Give the user permission. How you do that depend on the OS you’re running this on, and what access you have to the file system.

I can’t understand exactly.

This script is database backuping and restoring module for webtrees. And webtrees are using by admin only.
I writed this module and it gives error on some servers. http://www.backup.antenfiyati.com/webtrees/

When a PHP script runs on a web server it is beeing run as a user on that system. On some (horrible) configs PHP/apache/etc can be set to run as root, which means you will be able to read/write everything. In normal configs it will run as a user created for that spesific task, which may or may not have write access to the folder you are trying to write to.

You have to make sure the web server (apache, nginx, etc) and PHP has write permissions to the folder where you are trying to create a new folder.

Thanks for reply. Is there any amendment required in this code?
[php] if(!file_exists(BACKUPDIR)){
if (!mkdir(BACKUPDIR, 0777, true)) {
die(‘Failed to create folders…’);
}
}[/php]

When you upload a script to your server, you login, and hey server checks your username and pass.
Logs you in as user.
When your web server runs, it usually runs as another user.
Most other users dont have access to your files and folders, unless you give specific permissions to do so.
So when you run into a script that needs permission to create/read/modify/delete files/folders.
You have 2 options

  1. create files and folders and give world read/write permissions
  2. update the base folder with global read/write permissions

So nope, nothing you can do with the script.

Most people would opt for #1. and not give permissions to the base folder.

It’s way better to change the owner of the folder. chmod 777 is “the evilness”

Thank you to all of you

Sponsor our Newsletter | Privacy Policy | Terms of Service