简体   繁体   English

403在PHP mkdir上禁止

[英]403 Forbidden on php mkdir

I'm having a 403 Forbidden page when excecuting a php script with mkdir function. 使用mkdir函数执行php脚本时,我的页面为403 Forbidden。

here is the mkdir code: 这是mkdir代码:

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

I have tried 775, 666 permissions, but nothing. 我尝试了775、666的权限,但没有任何操作。 Insde the dir i want to store images, mp3's and videos. 我想要存储图像,mp3和视频的目录。 Can anyone help me? 谁能帮我?

UPDATE 1 更新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. 它应该使用从表单中给定的名称在目录“ uploads”中创建一个新目录,然后从文件夹中获取它的值“ folderName”,然后将表单中给定的文件上传到创建的新目录中。 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: 如果您使用'777',您将获得如下奇怪的权限:

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)." 原因(来自PHP chmod文档): “请注意,不会自动将模式假定为八进制值,因此,为确保预期的操作,您需要在模式前加上零(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." 我可以确认,尽管对整数处理进行了相关更改 ,PHP 7.0.3仍然会发生这种情况:“以前,包含无效数字的八进制立即被截断(0128被视为012)。现在,无效的八进制立即将引起解析。错误。”

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.) 不过,无论如何,默认值都是0777,它提供了尽可能广泛的访问权限,因此您无需指定它, 除非您想要设置任何以后的参数(例如,通常将第三个选项设置为true可以启用递归目录的创建,而不是在父级不存在时创建错误。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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