How to test if file upload is supported on server

2019-06-27 13:46发布

问题:

This is my code to test for MySQL:

if (extension_loaded('mysqlnd')) {
   echo "mysql supported";
} else {
   echo "mysql not supported";
};

How can I check to see if uploads are allowed?

回答1:

if(ini_get('file_uploads') == 1)
{
  echo 'HTTP Upload Enabled';
}
else
{
  echo 'HTTP Upload Disabled';
}


回答2:

PHP has the file_uploads INI setting:

Whether or not to allow HTTP file uploads. See also the upload_max_filesize, upload_tmp_dir, and post_max_size directives.

If you test that using ini_get(), you should be able to detect whether file uploads are enabled. (Make sure you test this, though.)

Theoretically, setting upload_max_filesize or post_max_size to a very low value could effectively block uploads as well. Also, file uploads could also be blocked on web server level. That will be impossible for you to detect without actually trying to do an upload.



回答3:

I dont think there's such thing like disabling file uploads and checking file upload support. You only can check things like, max allowed size, etc, like:


$maxSize = ini_get('post_max_size'); 

Hope it helps