求助:图片显示相关

求助:图片显示相关

我是一个菜鸟,在尝试自己写一个简单的产品发布的程序时遇到了一个问题,就是怎么样将图片的名称和存储路径写进数据库,并且在后台可以在一大堆图片中选出自己需要的图片,就像爱雪儿上传管理类那样的,求各位高手给个指点,谢了先!

我有个,也是到处搜来改的
这部分是上传的时候的
<?
$cnt=$_POST["cnt"];
$sub=$_POST["sub"];
$TimeLimit=60; /* 设置超时限制时间
                      缺省时间为 30 秒
                      设置为0时为不限时,这里设置的是60秒*/
                     
    @set_time_limit($TimeLimit);
    //设置超时显示的时间

if(upfile)
   {
                $uploaddir = "images/";
        // 上载文件存放路径
        if(preg_match('/([^\.]+)\.(...)$/i',$_FILES["upfile"]["name"],$match))
            $pic_ext=$match[2];
        $upfiles=date("U").".".$pic_ext;
                $uploadfile = $uploaddir.$upfiles;
        if (move_uploaded_file($_FILES['upfile']['tmp_name'], $uploadfile))
                   {     
                                 
                                 include("../link.php");
                                 link_data();
  $sql="insert into dxc_pics (dxc_pics_name,dxc_pics_sub,dxc_pics_cnt,dxc_pics_date)values ('$upfiles','$sub','$cnt',NOW())";
                                 $res=mysql_query($sql);
                                 if($res)
                                 echo "文件 $upfiles 上载成功!";
                                 else echo "文件 $upfiles 上载失败!";
            }
            else echo "文件 $upfiles 上载失败!";   
    }
  else  
     //如果没有选择文件进行上载,或者上载的文件大小超过了MAX_FILE_SIZE,提示、结束
    {
      echo "你没有选择任何文件上载,或者上载的文件超出了 $MAX_FILE_SIZE !";
     }
     @set_time_limit(30);
     // 恢复缺省超时设置


echo" <A HREF = add_pics.php>返回</A>";
?>


这部分是显示的
echo"<img src='tt.php?name=$name' alt='$content' border='1' style='border-color:#CCCCCC'>";

下面是tt.php
<?php
# Constants
define(IMAGE_BASE, 'upfile/images/');  //这里是你图片存放的路径
define(MAX_WIDTH, 150);
define(MAX_HEIGHT, 150);

# Get image location
$image_file=$_GET["name"];;
$image_path = IMAGE_BASE . "$image_file";

# Load image
$img = null;
$ext = strtolower(end(explode('.', $image_path)));
if ($ext == 'jpg' || $ext == 'jpeg') {
    $img = @imagecreatefromjpeg($image_path);
} else if ($ext == 'png') {
    $img = @imagecreatefrompng($image_path);
# Only if your version of GD includes GIF support
} else if ($ext == 'gif') {
    $img = @imagecreatefromgif($image_path);
}

# If an image was successfully loaded, test the image for size
if ($img) {

    # Get image size and scale ratio
    $width = imagesx($img);
    $height = imagesy($img);
    $scale = min(MAX_WIDTH/$width, MAX_HEIGHT/$height);

    # If the image is larger than the max shrink it
    if ($scale < 1) {
        $new_width = floor($scale*$width);
        $new_height = floor($scale*$height);

        # Create a new temporary image
        $tmp_img = imagecreatetruecolor($new_width, $new_height);

        # Copy and resize old image into new image
        imagecopyresized($tmp_img, $img, 0, 0, 0, 0,
                         $new_width, $new_height, $width, $height);
        imagedestroy($img);
        $img = $tmp_img;
    }
}

# Create error image if necessary
if (!$img) {
    $img = imagecreate(MAX_WIDTH, MAX_HEIGHT);
    imagecolorallocate($img,0,0,0);
    $c = imagecolorallocate($img,70,70,70);
    imageline($img,0,0,MAX_WIDTH,MAX_HEIGHT,$c2);
    imageline($img,MAX_WIDTH,0,0,MAX_HEIGHT,$c2);
        $text_color = imagecolorallocate($img, 233, 14, 91);
    imagestring($img, 1, 5, 5,  "A Simple Text String", $text_color);
}

# Display the image
header("Content-type: image/jpeg");
imagejpeg($img);

?>
哈哈,我现在就来!