Move_uploaded_file / overwrite



  • Part of my app allows users to upload a personalized image to act as the header/banner.
  • I don’t need to collect/store those images but one time. If they update with another banner, the old one needs to go away (unlink()).

The problem: When a user uploads the image file, it works the first time. When the user tries uploading a new image file, it appears that everything executes properly, but the old image remains.

Solutions tried:
Above move_upload_file(), I added:
chmod($target, 0755);

The above code was unsuccessful in solving the problem.
I read somewhere that it could most likely be due to not having permission to overwrite files from the app.

Any advice?


Sounds about right, could also be caching, have you purged and turned Varnish off before doing this? That’s worth a try.

What user owns the image file and who own the PHP files? Is it the same user? and is that user in the www group? That will tell you if it’s a permissions issue.

A quick fix to test would be to reset your app permissions in the Cloudways Platform Dashboard under Application Settings once your in the application’s settings itself (not server settings) and click that reset option in the middle.


To be clear Varnish does not work with PHP sites at all, its strictly for wordpress, drupal etc…