以编程方式设置用户图片的 Drupal 7 问题

2022-01-23 00:00:00 php drupal drupal-7

我正在使用脚本以编程方式在 Drupal 7 中设置用户图片.该脚本如下所示:Drupal 7 以编程方式保存用户图片.

I am using a script to programmatically set the user picture in Drupal 7. The script is depicted here: Drupal 7 save user picture programmatically.

脚本工作正常,但是一旦为特定用户设置了用户图片,并且如果我尝试删除该图片(作为管理员或用户本人),服务器将返回:

The script works fine, but once the user picture has been set for a specific user, and if I try to delete that picture (as an admin or as the user himself) the server returns:

警告:取消链接(/home/hkdepot/public_html/drupal_dev_4/sites/default/files/avatars/upload/b8f1e69e83aa12cdd3d2babfbcd1fe27_101.jpg):drupal_unlink() 中的权限被拒绝(/home/hkdepot/public_html/drupal_dev_4/的第 2199 行包括/file.inc).

Warning: unlink(/home/hkdepot/public_html/drupal_dev_4/sites/default/files/avatars/upload/b8f1e69e83aa12cdd3d2babfbcd1fe27_101.jpg): Permission denied in drupal_unlink() (line 2199 of /home/hkdepot/public_html/drupal_dev_4/includes/file.inc).

文件不会从文件夹中删除.

The file does not get deleted from the folder.

这是我应该担心的吗?这是设置图片时的权利问题吗?我该如何处理?

Is this anything I should worry about? Is that a right's issue when setting the picture? How do I deal with it?

推荐答案

775 = rwxrwxr-x = 用户:读写执行;组:读写执行;世界:读取、执行

这只是意味着试图删除文件(可能是 www-data)的用户不是所有者,也不是所有权组.所以你要么需要

It just means that the user that is trying to delete the file (likely www-data) is not the owner nor is it in the ownership group. So you either need to

  1. 设置文件权限为777
  2. 将所有者更改为要删除的用户
  3. 将要删除的用户添加到组中

进一步阅读:

  • Linux 文件权限位掩码
  • 如何在 Linux 中更改文件的所有者和组

相关文章