[英]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.