zachleigh's avatar

Cron job to remove storage files

Users on my site can upload a profile picture and they can preview the picture before selecting it. Im using Intervention/image URL manipulation to serve the pics so in order to let the users see what their pics will actually look like on the site, Im sending them via ajax to my server, saving them in a temp directory in storage, and then setting the src on the profile to the temporary image url. Works great.

However, I cant find a good way to keep the temp directory clean. Ideally, I would like to do a cron job to wipe out all the files older than 10 minutes every ten minutes or so, but Im having permission issues. Although storage itself is owned by my user, the created files are all owned by www-data so my command to delete them fails with a permission denied error. How can I fix this? Is there a better way to handle this?

0 likes
2 replies
zachleigh's avatar

Thanks @jimmck Im using Ubuntu. I had to reinstall recently and I forgot to add my user to the www-data group after. I think this might solve the issue.

Please or to participate in this conversation.