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条)

报告相同问题?

悬赏问题

  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?