简体   繁体   English

如何为我的Laravel应用程序授予权限在目录中创建子文件夹(Ubuntu)

[英]How to give permission for my Laravel application create subfolders in a directory (Ubuntu)

I have a folder that will be the container for subfolders created by user of my application. 我有一个文件夹,它将是我的应用程序用户创建的子文件夹的容器。 I use the following commands to let my application execute the mkdir() function: "sudo chmod -R 775 /var/www/laravel/public/folder_want_give_permission_to", "sudo chmod -R 777 /var/www/laravel/public/folder_want_give_permission_to", "chown -R www-data:www-data folder_want_to_give_permission_to". 我使用以下命令让我的应用程序执行mkdir()函数:“ sudo chmod -R 775 / var / www / laravel / public / folder_want_give_permission_to”,“ sudo chmod -R 777 / var / www / laravel / public / folder_want_give_permission_to ”,“ chown -R www-data:www-data folder_want_to_give_permission_to”。 As I am testing my application, visiting the pages that execute the mkdir function, I have to run the commands from time to time because it appears that Ubuntu "forgets" that I allowed permission in the directory and I get "ErrorException: mkdir(): Permission denied". 当我测试应用程序时,访问执行mkdir函数的页面,我不得不不时地运行命令,因为看来Ubuntu忘记了我在目录中允许的权限,并且我得到了ErrorError:mkdir() : 没有权限”。 Things get worse when I remove all subfolders from the directory that I gave permission, the error appears right after I create the first subfolder. 当我从我授予权限的目录中删除所有子文件夹时,情况变得更糟,该错误在我创建第一个子文件夹后立即出现。 The Ubuntu version I am using is 16.04. 我正在使用的Ubuntu版本是16.04。

To show my mkdir() I think I have to explain the variable values involved. 为了显示我的mkdir(),我认为我必须解释所涉及的变量值。

My system counts the number of subdirectories to manage the user directories to avoid creating directories with the same name. 我的系统计算子目录的数量来管理用户目录,以避免创建具有相同名称的目录。 To create a user directory I use the code below. 要创建用户目录,请使用以下代码。

mkdir( $userdirectory, 0755, true);

$userDirectory would have a value like this, if the user was the first user to register. 如果该用户是第一个注册用户,则$ userDirectory将具有这样的值。

"/var/www/laravel/public/folder_want_to_give_permission_to/1" “ / var / www / laravel / public / folder_want_to_give_permission_to / 1”

This would create a subdirectory inside the folder I want to grant permission for them create additional subfolders to store images. 这将在我要授予权限的文件夹内创建一个子目录,并创建其他子文件夹来存储图像。

Now to create the subfolders to store images inside the user folder. 现在创建子文件夹以将图像存储在用户文件夹中。

mkdir( $userdirectory. $numSubDir, 0755, true);

$folder has a value something like this "/var/www/laravel/public/folder_want_to_give_permission_to/1/" and $numSubdir stores a number like "1" or "2" to store images. $ folder的值类似于“ / var / www / laravel / public / folder_want_to_give_permission_to / 1 /”,而$ numSubdir存储诸如“ 1”或“ 2”的数字以存储图像。

I would end up with something like this: /var/www/laravel/public/folder_want_to_give_permission_to/1/1 我最终会遇到这样的事情:/ var / www / laravel / public / folder_want_to_give_permission_to / 1/1

So a user could have directories to store images like this: 因此,用户可以具有用于存储图像的目录,如下所示:

/var/www/laravel/public/folder_want_to_give_permission_to/1/1
/var/www/laravel/public/folder_want_to_give_permission_to/1/2

another user 另一个使用者

/var/www/laravel/public/folder_want_to_give_permission_to/2/1
/var/www/laravel/public/folder_want_to_give_permission_to/2/2

if what I am trying to do isn't clear: /var/www/laravel/public/folder_want_to_give_permission_to/user_directory/folder_to_store_images_1 如果我尝试做的事情不清楚:/ var / www / laravel / public / folder_want_to_give_permission_to / user_directory / folder_to_store_images_1

/var/www/laravel/public/folder_want_to_give_permission_to/user_directory/folder_to_store_images_2

a 一种

Please run the below command, hope this helps. 请运行以下命令,希望对您有所帮助。

sudo chown -R www-data:www-data /var/www/laravel/ 须藤chown -R www-data:www-data / var / www / laravel /

暂无
暂无

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

相关问题 如何在我的 Laravel 应用程序中为存储目录分配权限 - how to assign permission to storage directory in my laravel application Laravel 5.8 - 如何授予用户阅读、创建、更新、删除的权限? - Laravel 5.8 - How to give permission to users to read,create,update,delete? 如何授予 apache 写入主目录的权限? - How to give apache permission to write to home directory? Laravel 5.0对Ubuntu的许可 - Laravel 5.0 Permission on ubuntu Laravel创建存储文件夹子文件夹 - Laravel create storage folder subfolders 如何授予 apache (lamp) 在 opensuse tumbleweed 中创建目录或文件的权限? - How to give apache (lamp) permission to make directory or a file in opensuse tumbleweed? 如何遍历文件夹和子文件夹并使用Laravel创建? - How to loop throught folders and subfolders and create using Laravel? laravel 5.2如何在应用程序中创建简单搜索 - laravel 5.2 how can i create simple search in my application 如何使用PHP创建文件夹和子文件夹,用户可以给出自己的名称和要创建的文件夹数 - How to create folders and subfolders using PHP where user can give his own NAME and number of folders to be created Laravel 并做出反应,如何从 Laravel 向我的反应应用程序发出通知(意外使用“自我”没有受限全局错误) - Laravel and react, How to give a notification from Laravel to my react application (Unexpected use of 'self' no restricted-globals error)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM