コード例 #1
0
function get_config_bytes($val)
{
    $val = trim($val);
    $last = strtolower($val[strlen($val) - 1]);
    switch ($last) {
        case 'g':
            $val *= 1024;
        case 'm':
            $val *= 1024;
        case 'k':
            $val *= 1024;
    }
    return fix_integer_overflow($val);
}
コード例 #2
0
ファイル: fileUpload.php プロジェクト: HeuristNetwork/heurist
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;
}
コード例 #3
0
ファイル: io_dzz.php プロジェクト: druphliu/dzzoffice
 public function save($target, $filename)
 {
     global $_G;
     $filepath = $_G['setting']['attachdir'] . $target;
     $md5 = md5_file($filepath);
     $filesize = fix_integer_overflow(filesize($filepath));
     if ($md5 && ($attach = DB::fetch_first("select * from %t where md5=%s and filesize=%d", array('attachment', $md5, $filesize)))) {
         $attach['filename'] = $filename;
         $pathinfo = pathinfo($filename);
         $ext = $pathinfo['extension'] ? $pathinfo['extension'] : '';
         $attach['filetype'] = strtolower($ext);
         @unlink($filepath);
         return $attach;
     } else {
         $pathinfo = pathinfo($filename);
         $ext = $pathinfo['extension'] ? $pathinfo['extension'] : '';
         $pathinfo1 = pathinfo($target);
         $ext_dzz = strtolower($pathinfo1['extension']);
         if ($ext_dzz == 'dzz') {
             $unrun = 1;
         } else {
             $unrun = 0;
         }
         $filesize = filesize($filepath);
         $remote = 0;
         $attach = array('filesize' => $filesize, 'attachment' => $target, 'filetype' => strtolower($ext), 'filename' => $filename, 'remote' => $remote, 'copys' => 0, 'md5' => $md5, 'unrun' => $unrun, 'dateline' => $_G['timestamp']);
         if ($attach['aid'] = DB::insert('attachment', $attach, 1)) {
             $remoteid = io_remote::getRemoteid($attach);
             if ($_G['setting']['thumb_active'] && $remoteid < 2 && in_array($attach['filetype'], array('jpg', 'jpeg', 'png'))) {
                 //主动模式生成缩略图
                 try {
                     self::createThumb('dzz::' . $attach['attachment'], 256, 256);
                 } catch (Exception $e) {
                 }
             }
             C::t('local_storage')->update_usesize_by_remoteid($attach['remote'], $attach['filesize']);
             dfsockopen($_G['siteurl'] . 'misc.php?mod=movetospace&aid=' . $attach['aid'] . '&remoteid=0', 0, '', '', false, '', 1);
             return $attach;
         } else {
             return false;
         }
     }
 }