Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: copy() is messing up file permissions somehow

Tags:

php

apache

ftp

I have an image uploader on my site...

The image is uploaded to a temporary 777 folder (this image works fine and can be deleted), I then copy this file into a new dir with copy() the new file is written to a 777 folder, but cannot be deleted. chmod() doesn't seem to help...

Why does the copy() function create the new file somehow different to the original file? I can't see any differences in my FTP client. BOTH have perms 644 and user 'nobody/99' - but it's only a problem for the second file.

Any ideas?

like image 964
Haroldo Avatar asked Dec 17 '25 15:12

Haroldo


1 Answers

You need to manually set the permissions bits yourself: try this.

copy($temp_img_url, $save_file_as); chmod($save_file_as, fileperms($temp_img_url));
like image 185
Femi Avatar answered Dec 20 '25 07:12

Femi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!