示例#1
0
function file_argument($media_type, $name, $default = null)
{
    $mime = check_media_type($media_type);
    // upload file
    if (isset($_FILES[$name])) {
        if ($_FILES[$name]['error'] == UPLOAD_ERR_OK) {
            $destination = get_upload_path($mime, $_FILES[$name]['name']);
            move_uploaded_file($_FILES[$name]['tmp_name'], $destination['path']);
            $media_url = $destination['url'];
        } else {
            throw new HttpError('file upload error: ' . $_FILES[$name]['error'], HttpError::BadRequest);
        }
    } else {
        if ($default !== null) {
            return $default;
        }
        throw new HttpError("argument {$name} missing", HttpError::BadRequest);
    }
    return $media_url;
}
示例#2
0
             }
         }
         closedir($handle);
     }
     foreach ($image_list_all as $key => $val) {
         sort($image_list_all[$key]);
     }
     $sql = "SELECT cat_id\r\n\t\t\t\t\t\tFROM " . CATEGORIES_TABLE;
     $result = $site_db->query($sql);
     while ($row = $site_db->fetch_array($result)) {
         $cat_id = $cats[] = $row['cat_id'];
         $cat_path = $cat_id == 0 ? "" : "/" . $cat_id;
         if ($handle = opendir(MEDIA_PATH . $cat_path)) {
             while ($file = @readdir($handle)) {
                 if ($file != "." && $file != "..") {
                     if (check_media_type($file)) {
                         $image_list_all[$row['cat_id']][] = $file;
                     }
                 }
             }
             closedir($handle);
         }
     }
     foreach ($image_list_all as $key => $val) {
         sort($image_list_all[$key]);
     }
     $cat_sql = implode(", ", $cats);
 }
 $sql = "SELECT image_media_file, cat_id\r\n\t\t\t\t\tFROM " . IMAGES_TABLE . "\r\n\t\t\t\t\tWHERE cat_id IN ({$cat_sql})\r\n\t\t\t\t\tORDER BY cat_id";
 $result = $site_db->query($sql);
 while ($row = $site_db->fetch_array($result)) {
示例#3
0
function get_thumbnail_code($media_file_name, $thumb_file_name = "", $image_id, $cat_id, $image_name = "", $mode = "", $show_link = 1, $open_window = 0)
{
    global $site_sess, $config;
    if (!check_media_type($media_file_name)) {
        $thumb = "<img src=\"" . ICON_PATH . "/404.gif\" border=\"0\" alt=\"\" />";
    } else {
        if (!get_file_path($thumb_file_name, "thumb", $cat_id, 0, 0)) {
            $file_src = ICON_PATH . "/" . get_file_extension($media_file_name) . ".gif";
            $image_info = @getimagesize($file_src);
            $width_height = !empty($image_info[3]) ? " " . $image_info[3] : "";
            $thumb = "<img src=\"" . $file_src . "\" border=\"0\"" . $width_height . " alt=\"" . format_text($image_name, 2) . "\" title=\"" . format_text($image_name, 2) . "\" />";
        } else {
            $file_src = get_file_path($thumb_file_name, "thumb", $cat_id, 0, 1);
            $image_info = @getimagesize($file_src);
            $width_height = !empty($image_info[3]) ? " " . $image_info[3] : "";
            $thumb = "<img src=\"" . $file_src . "\" border=\"" . $config['image_border'] . "\"" . $width_height . " alt=\"" . format_text($image_name, 2) . "\" title=\"" . format_text($image_name, 2) . "\" />";
        }
    }
    if ($show_link) {
        if ($open_window) {
            $thumb = "<a href=\"" . $site_sess->url(ROOT_PATH . "details.php?" . URL_IMAGE_ID . "=" . $image_id . (!empty($mode) ? "&amp;mode=" . $mode : "")) . "\" onclick=\"opendetailwindow()\" target=\"detailwindow\">" . $thumb . "</a>";
        } else {
            $thumb = "<a href=\"" . $site_sess->url(ROOT_PATH . "details.php?" . URL_IMAGE_ID . "=" . $image_id . (!empty($mode) ? "&amp;mode=" . $mode : "")) . "\">" . $thumb . "</a>";
        }
    }
    return $thumb;
}