2014-09-13 75 views
2

我想使用mkdir()函數,該函數允許我從該目錄中獲取要添加到我的html/php頁面的圖像,但該目錄中的任何內容都不可執行(因爲我允許將圖像上傳到該目錄中)...所以即使有人設法通過我的安全檢查並上傳一個.php文件,它也不應該能夠運行。PHP:使目錄只允許讀取文件

mkdir()應該使用哪些權限/選項來執行此操作?

我知道這也可以用.htaccess文件完成,如果你可以用mkdir和.htaccess文件代碼來回答,我會非常感激!

在此先感謝!

+0

這是什麼意思? 'mkdir()'中設置了什麼值?你的意思是八進制值? – Ghost 2014-09-13 09:54:04

+0

不,我的意思是模式值,例如默認是「0777」 – Ryan 2014-09-13 09:54:58

+0

是的那就是八進制值:) – Ghost 2014-09-13 09:55:15

回答

1

那麼你可以只用這個作爲參考:

octal number to represent mode/permission: 
r: 4 
w: 2 
x: 1 

Read, write and execute (full) 
0+r+w+x = 0+4+2+1 = 7 

Only Read and write permission on a file in octal is 
0+r+w+x = 0+4+2+0 = 6 

Only read and execute permission on a file in octal is 
0+r+w+x = 0+4+0+1 = 5 

User = r+w+x = 0+4+2+1 = 7 
Group= r+w+x = 0+4+2+0 = 6 
Others = r+w+x = 0+0+0+1 = 1 

然後用它mkdir()根據:

mkdir('path/to/directory/', 0555); // read execute/444 readonly 

如果仍然沒有工作,你可以明確地使用chmod()吧:

chmod('/directory/', 0555); 
+0

會試試看並回來:) 任何有關htaccess文件的想法? – Ryan 2014-09-13 10:00:25

+0

@瑞安對不起,我沒有那個部分的答案 – Ghost 2014-09-13 10:01:07

+0

好的,這對我很有幫助,謝謝! – Ryan 2014-09-13 10:08:30