A catch-all function to check that a folder is able to handle file uploads. In addition to the standard check that the folder specified exists, is readable and is writable, it also checks your server’s PHP installation to confirm that the temporary upload folder is in fact valid. Up until this point I’ve always naively assumed that the smart folks who set up servers know to configure that value properly. But a couple of chaps on the Form Tools forums found that their installations of PHP had invalid settings – or weren’t set at all. Doh!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | /*------------------------------------------------------------------------------------------------*\ Function: check_upload_folder Description: examines a folder to check (a) it exists and (b) it has correct permissions. This function also checks to see if the upload_temp_dir server setting has been configured. Parameter: the full path to the folder to be examined. \*------------------------------------------------------------------------------------------------*/ function check_upload_folder($folder) { // first, check server's temporary file upload folder $upload_tmp_dir = ini_get("upload_tmp_dir"); if (empty($upload_tmp_dir)) return array(false, "Your server's installation of PHP doesn't appear to have the <b>upload_tmp_dir</b> setting configured. This setting determines where files are temporarily uploaded to before they are moved to the folder you are specifying here. This value needs to be set in order to allow this program to properly upload files. Please contact your hosting provider."); if (!is_dir($folder)) return array(false, "Your server's installation of PHP has an invalid setting for the <b>upload_tmp_dir</b> value. \"$upload_tmp_dir\" is not a valid folder."); if (!is_writable($folder)) return array(false, "This temporary upload folder specified by your PHP installation is not writable. Until this is fixed, files cannot be uploaded through any PHP program on your server. Please contact your hosting provider."); // now check the folder specified by if (!is_dir($folder)) return array(false, "This is not a valid folder."); if (!is_writable($folder)) return array(false, "This folder is not writeable."); return array(true, "This folder has the correct permissions."); } |
Recent Comments