Esempio n. 1
0
function postmode_file_selection()
{
    $param_name = 'file';
    // there are two ways into the file selection mode;
    // either the user has just arrived at the import page,
    // or they've selected a file *and might progress to file-parsing mode*
    $error = '';
    if (@$_FILES[$param_name]) {
        if ($_FILES[$param_name]['size'] == 0) {
            $error = 'no file was uploaded';
        } else {
            //DEBUG print $_FILES['import_file']['error'];
            switch ($_FILES[$param_name]['error']) {
                case UPLOAD_ERR_OK:
                    break;
                case UPLOAD_ERR_INI_SIZE:
                case UPLOAD_ERR_FORM_SIZE:
                    $error = "The uploaded file was too large.  Please consider importing it in several stages.";
                    break;
                case UPLOAD_ERR_PARTIAL:
                    $error = "The uploaded file was only partially uploaded.";
                    break;
                case UPLOAD_ERR_NO_FILE:
                    $error = "No file was uploaded.";
                    break;
                case UPLOAD_ERR_NO_TMP_DIR:
                    $error = "Missing a temporary folder.";
                    break;
                case UPLOAD_ERR_CANT_WRITE:
                    $error = "Failed to write file to disk";
                    break;
                default:
                    $error = "Unknown file error";
            }
            $content_length = fix_integer_overflow((int) @$_SERVER['CONTENT_LENGTH']);
            $post_max_size = get_config_bytes(ini_get('post_max_size'));
            if ($post_max_size && $content_length > $post_max_size) {
                $error = 'The uploaded file exceeds the post_max_size directive in php.ini';
            } else {
                if ($_FILES[$param_name]['tmp_name'] && is_uploaded_file($_FILES[$param_name]['tmp_name'])) {
                    $file_size = get_file_size($_FILES[$param_name]['tmp_name']);
                } else {
                    $file_size = $content_length;
                }
                $file_max_size = get_config_bytes(ini_get('upload_max_filesize'));
                if ($file_max_size && $content_length > $file_max_size) {
                    $error = 'The uploaded file exceeds the upload_max_filesize directive in php.ini';
                }
            }
            print $error;
        }
        if (!$error) {
            // move on to the next stage!
            //$error = postmode_file_load_to_db($_FILES[$param_name]['tmp_name'], $_FILES[$param_name]['name'], true);
        }
    }
    return $error;
}
 * @author      Artem Osmakov   <*****@*****.**>
 * @license     http://www.gnu.org/licenses/gpl-3.0.txt GNU License 3.0
 * @version     4.0
 */
/*
 * Licensed under the GNU License, Version 3.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at http://www.gnu.org/licenses/gpl-3.0.txt
 * Unless required by applicable law or agreed to in writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied
 * See the License for the specific language governing permissions and limitations under the License.
 */
define('MANAGER_REQUIRED', 1);
define('PDIR', '../../../');
require_once dirname(__FILE__) . "/../initPage.php";
$post_max_size = get_config_bytes(ini_get('post_max_size'));
$file_max_size = get_config_bytes(ini_get('upload_max_filesize'));
function fix_integer_overflow($size)
{
    if ($size < 0) {
        $size += 2.0 * (PHP_INT_MAX + 1);
    }
    return $size;
}
function get_config_bytes($val)
{
    $val = trim($val);
    $last = strtolower($val[strlen($val) - 1]);
    switch ($last) {
        case 'g':
            $val *= 1024;
        case 'm':