dongliao1860 2016-08-11 09:55
浏览 90
已采纳

PHP mkdir()在浏览器中不起作用[重复]

This question already has an answer here:

I'm trying to create directory on my local apache server with php.
I tried
<?php mkdir("folder"); ?>
and
<?php exec("sudo mkdir folder"); ?>
When I try to execute them in browser nothing happens.
But I can execute them from terminal by using sudo. (I also modified sudoers file so it won't prompt for password in second code)
When I don't use sudo I get this error
PHP Warning: mkdir(): Permission denied in /var/www/html/mscr/add.php on line 2

I've also tried this and this .

So I can execute almost everything but directory operations in browser. I want to be able to create, delete and edit directories in browser.

Thank you!

</div>
  • 写回答

2条回答 默认 最新

  • douba05167 2016-08-11 10:02
    关注

    Sounds like Apache doesn't have permission to create the folder. Either give Apache ownership of the folder (where you're trying to create a new one)

    sudo chown www-data /var/www/html/mscr
    

    or set the folder permissions to 777

    sudo chmod 777 /var/www/html/mscr
    

    Warning this will make everything within the mscr folder executable. To get around this most CMS will create a subfolder which is set to 777 so something like /var/www/html/mscr/uploads

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)