CreativeDream / php-uploader

PHP File Uploader is an easy to use, hi-performance File Upload Script which allows you to upload files to webserver
MIT License
94 stars 51 forks source link

Permissions for files and directories on linux #19

Open gloventRehan opened 7 years ago

gloventRehan commented 7 years ago

PLEASE change chmod and mkdir permissions to 0750 (leading zero for octal representation) , it is currently as 750 so linux messes things up when you want to rmdir and all file permissions are also incorrect.

http://php.net/manual/en/function.chmod.php

(I wanted to branch and commit to that branch changes but couldn't ,wasted so much time on two missing 0, but further great library thanks)

answerquest commented 7 years ago

Hi @gloventRehan I'm not a programmer, want to use this in our local network. Running on apache/php server on my Ubuntu 16.04 laptop. Could you confirm that it's these two lines in php-uploader/src/class.uploader.php that need changing the 750 to 0750:

Line 150 if(!file_exists($options['uploadDir']) && !is_dir($options['uploadDir']) && mkdir($options['uploadDir'], 750, true)){

Line 154 if(!is_writable($options['uploadDir'])) @chmod($options['uploadDir'], 750);

Please also tell if it should be enclosed in quotes now or should be left without quotes.

gloventRehan commented 7 years ago

That is correct so

Line 150 becomes: if(!file_exists($options['uploadDir']) && !is_dir($options['uploadDir']) && mkdir($options['uploadDir'], 0750, true)){

Line 154 becomes: if(!is_writable($options['uploadDir'])) chmod($options['uploadDir'], 0750);

Also note in Line 154 the @ sign is removed, the developers put this here to suppress any errors that this function generate. This is why it worked while I tested on windows and why it did not work and took many hours to find on the linux server. So I also highly recommend removing the @ sign before chmod, otherwise you will be left pulling your hair out to find out why your documents are not being uploaded. This way, it will warn you if it could not change the directory permissions and you can do so while testing before shipping your code to production.