Drupal 7 issue with programmatically set user pict

2019-09-03 10:42发布

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:

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?

1条回答
爷的心禁止访问
2楼-- · 2019-09-03 11:00

775 = rwxrwxr-x = User: Read Write Execute; Group: Read Write Execute; World: Read, Execute

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. Set the file permissions to 777
  2. Change the owner to the user who is deleteing
  3. Add the user who is deleting to the group

Further reading:

查看更多
登录 后发表回答