WikiDocs icon indicating copy to clipboard operation
WikiDocs copied to clipboard

Limit file size upload

Open ffiesta opened this issue 1 year ago • 6 comments

Hey guys

I don't know how to work with the git system, so I leave the change here

Add code (line 509)

	 // check file size (limit to 10 MB)
    if($attachment['size'] > 10 * 1024 * 1024) {
        // error
        echo json_encode(array("error"=>1,"code"=>"file_too_large","size"=>$attachment['size']));
        // return
        return false;
    }

after end tag } of code

// error
		echo json_encode(array("error"=>1,"code"=>"file_not_allowed","file"=>$attachment));
		// return
		return false;
	}

Please review security

ffiesta avatar Mar 05 '24 15:03 ffiesta

File size is also limited by your web-server AND php.

nginx in any server, http or location:

client_max_body_size 10M;

apache in .htaccess:

LimitRequestBody 10485760

php in php.ini (most likely the fpm one):

upload_max_filesize = 10M

You'll get a 413 Request Entity Too Large from your web-server or file_error from php if you exceed these.

TheNeoBurn avatar Mar 26 '24 12:03 TheNeoBurn

Thanks @TheNeoBurn.

However, I have a question: what is the best way to implement ensuring the addition of the upload value through wikidocs menu?

Thanks,

ffiesta avatar Mar 26 '24 13:03 ffiesta

@ffiesta,

The issue is that both the web-server and php set the upper limit for WikiDocs as long as it uses the default file upload method. This means that WikiDocs could only ever be configured below these limits.

If WikiDocs works under a general web-server with a huge file upload setting or if it changes to another method for uploading big files then yes, this would be a nice feature.

Note: Also, I did the pull-request thing for the first time here today and can now tell you how: Create a fork, edit the code in your own repository created by the fork, then return to this repository and GitHub will scream at you that you have changes and asks you to create a pull request.

TheNeoBurn avatar Mar 26 '24 14:03 TheNeoBurn

Done, but

  • on php > 8.0 + it give an error [30-Mar-2024 14:32:26 UTC] PHP Warning: Undefined array key "document" in /home/pmtpt1/public_html/wiki/submit.php on line 456
  • on php > 8.1 + it give an error on same line but show that deprecated strtolower()

ffiesta avatar Mar 30 '24 14:03 ffiesta

hi @ffiesta, at this moment wiki|docs is based on php 7.. we have not ready yet converted it to fully support php 8. i will try to do this conversion in the next months i am very busy with my work in this period, sorry!

Zavy86 avatar Apr 14 '24 08:04 Zavy86

Hi @Zavy86, yap this work with php 7.

In future i will try to make a menu.

Thanks

ffiesta avatar Apr 14 '24 09:04 ffiesta