简体   繁体   中英

403 Forbidden on php mkdir

I'm having a 403 Forbidden page when excecuting a php script with mkdir function.

here is the mkdir code:

mkdir('uploads/'.$upload_folder.'/', 777)

I have tried 775, 666 permissions, but nothing. Insde the dir i want to store images, mp3's and videos. Can anyone help me?

UPDATE 1

here is the whole script:

$folderStr = $_REQUEST['folderName'];

//create SEO firndly directory name
$upload_folder =    preg_replace("'\s+'", '-', $folderStr);

// The place the files will be uploaded to (currently a 'files' directory).
$upload_path = 'uploads/'.$upload_folder.'/';

//Check whether folder exists or create with the name supplied
if(is_dir($upload_folder))
echo 'directory exists';
else
mkdir('uploads/'.$upload_folder.'/', 777);

It supposed to make a new directory into the folder "uploads" with the name given from the form which i get it from there with value 'folderName', and upload the files given from the form into the new dir which is created. Also it can't write greek characters on the foldername. what i have to change to make it work?

You need a zero in front of the desired mode, eg

mkdir('uploads/'.$upload_folder.'/', 0777)

If you use '777', you will get strange permissions like this:

dr----x--t

instead of this:

drwxrwxr-x

Reason (from PHP chmod docs): "Note that mode is not automatically assumed to be an octal value, so to ensure the expected operation, you need to prefix mode with a zero (0)."

I can confirm that this still happens in PHP 7.0.3, despite related changes to integer handling : "Previously, octal literals that contained invalid numbers were silently truncated (0128 was taken as 012). Now, an invalid octal literal will cause a parse error."

However 0777 is the default anyway, which gives the widest possible access, so you do not need to specify it, unless you want to set any later parameters (eg often it's useful to set the third option to true to enable creation of recursive directories, rather than creating an error if the parent doesn't exist.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM