[ Index ] |
|
Code source de Phorum 5.1.25 |
1 <?php 2 3 //////////////////////////////////////////////////////////////////////////////// 4 // // 5 // Copyright (C) 2006 Phorum Development Team // 6 // http://www.phorum.org // 7 // // 8 // This program is free software. You can redistribute it and/or modify // 9 // it under the terms of either the current Phorum License (viewable at // 10 // phorum.org) or the Phorum License that was distributed with this file // 11 // // 12 // This program is distributed in the hope that it will be useful, // 13 // but WITHOUT ANY WARRANTY, without even the implied warranty of // 14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. // 15 // // 16 // You should have received a copy of the Phorum License // 17 // along with this program. // 18 //////////////////////////////////////////////////////////////////////////////// 19 20 // Check if the Phorum file uploading settings match the 21 // limits that are imposed by the system. 22 23 // TODO (document in faq / documentation) 24 // The upload size can be limited by Apache's LimitRequestBody directive, 25 // but we cannot check that one from PHP. 26 27 require_once ('./include/format_functions.php'); // For phorum_filesize() 28 require_once ('./include/upload_functions.php'); 29 30 $phorum_check = "File uploading (personal files and attachments)"; 31 32 function phorum_check_upload_limits() { 33 $PHORUM = $GLOBALS["PHORUM"]; 34 35 // Keep track if uploads are used. 36 $upload_used = false; 37 38 // Get the maximum file upload size for PHP. 39 list ($system_max_upload, $php_max_upload, $db_max_upload) = phorum_get_system_max_upload(); 40 41 // Check limits for file uploading in personal profile. 42 if ($PHORUM["file_uploads"] && $PHORUM["max_file_size"]) { 43 $upload_used = true; 44 $res = phorum_single_check_upload_limits( 45 $PHORUM["max_file_size"]*1024, 46 "the Max File Size option for user file uploads " . 47 "(in their profile)", 48 $php_max_upload, $db_max_upload 49 ); 50 if ($res != NULL) return $res; 51 } 52 53 // Check limits for attachment uploading in forums. 54 $forums = phorum_db_get_forums(); 55 foreach ($forums as $id => $forum) { 56 if ($forum["max_attachments"] > 0 && $forum["max_attachment_size"]) { 57 $upload_used = true; 58 $res = phorum_single_check_upload_limits( 59 $forum["max_attachment_size"]*1024, 60 "the Max File Size option for uploading attachments 61 in the forum \"{$forum['name']}\"", 62 $php_max_upload, $db_max_upload 63 ); 64 if ($res != NULL) return $res; 65 } 66 } 67 68 // No upload functionality found so far? Then we're done. 69 if (! $upload_used) return array(PHORUM_SANITY_OK, NULL); 70 71 // Check if the upload temp directory can be written. 72 $tmpdir = get_cfg_var('upload_tmp_dir'); 73 if (!empty($tmpdir)) { 74 $fp = @fopen("$tmpdir/sanity_checks_dummy_uploadtmpfile", "w"); 75 if (! $fp) return array( 76 PHORUM_SANITY_CRIT, 77 "The system is unable to write files 78 to PHP's upload tmpdir \"".htmlspecialchars($tmpdir)."\". 79 The system error was:<br/><br/>". 80 htmlspecialchars($php_errormsg).".", 81 "Change the upload_tmp_dir setting in your php.ini file 82 or give your webserver more permissions for the current 83 upload directory." 84 ); 85 86 fclose($fp); 87 unlink("$tmpdir/sanity_checks_dummy_uploadtmpfile"); 88 } 89 90 return array(PHORUM_SANITY_OK, NULL); 91 } 92 93 // ======================================================================== 94 // Helper functions 95 // ======================================================================== 96 97 // We have to check multiple upload limits. Using this function, 98 // we do not have to rebuild all error messages over and over 99 // again. 100 function phorum_single_check_upload_limits ($howmuch, $what, $maxphp, $maxdb) 101 { 102 // Check PHP limits. 103 if (!empty($maxphp) && $howmuch > $maxphp) return array( 104 PHORUM_SANITY_WARN, 105 "You have configured ".htmlspecialchars($what)." to ". 106 phorum_filesize($howmuch).". Your PHP installation only 107 supports ".phorum_filesize($maxphp).". Your users might 108 have problems with uploading their files because of this.", 109 "Raise the options post_max_size and upload_max_filesize in your 110 php.ini file to match the Max File Size option or lower this 111 configuration option for your forums." 112 ); 113 114 // Check database limits. 115 if (!empty($maxdb) && $howmuch > $maxdb) return array( 116 PHORUM_SANITY_WARN, 117 "You have configured ".htmlspecialchars($what)." to ". 118 phorum_filesize($howmuch).". Your database only supports ". 119 phorum_filesize($maxdb).". Your users might have problems with 120 uploading their files because of this.", 121 "Configure your database to allow larger packets or lower the 122 Max File Size configuration option for your forums." 123 ); 124 125 return NULL; 126 } 127 128 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Nov 29 12:22:27 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |