Kichu
Kichu

Reputation: 3267

How to test if file upload is supported on server using php

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?

Upvotes: 5

Views: 5107

Answers (3)

Zul
Zul

Reputation: 3608

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

Upvotes: 15

Pekka
Pekka

Reputation: 449613

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.

Upvotes: 0

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100195

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

Upvotes: -1

Related Questions