0

我正在使用此代码从文章表单中获取数据,以保存文章的图像并将它们显示在新闻滑块中:

if(isset($_POST['submit']))
{
unset($_SESSION['firsttitle']);
unset($_SESSION['firstcontent']);
unset($_SESSION['title']);
unset($_SESSION['content']);
unset($_SESSION['thirdcontent']);


$_SESSION['title']=mysql_real_escape_string(trim($_POST['title']));
$_SESSION['content']=mysql_real_escape_string(trim($_POST['content']));
$weight=htmlentities(trim($_REQUEST['weight']),ENT_QUOTES);
$id=$_REQUEST['id'];
$time=mktime();

if($_FILES['picture']['name'])
    {
    $select="select * from ".$prev."news where id='$id'";
    $re_select=mysql_query($select);
    $d_select=mysql_fetch_array($re_select);

    if($d_select['picture']!='')
    {
    unlink("../".$d_select['picture']);
    }
    $picture="upload/".$time.$_FILES['picture']['name'];
    $path="../".$picture;

    move_uploaded_file($_FILES['picture']['tmp_name'],$path);
}
else
{
    $picture=$_POST['picturepath'];
}



if($id=='0' || !$_REQUEST['id'])
{
    $insert="insert into ".$prev."news (title,content,weight,picture,status,postedtime) values('".$_SESSION['title']."','".$_SESSION['content']."','$weight','$picture','Y','$time')";

    mysql_query($insert);
    $lastid=mysql_insert_id();
    unset($_SESSION['title']);
    unset($_SESSION['content']);
    @header("location:news-addnew.php?id=$lastid");
}
else
{
    $update="update ".$prev."news set  title='".$_SESSION['title']."',content='".$_SESSION['content']."',weight='$weight',picture='$picture',status='$status',postedtime='$time' where id='$id'";

    mysql_query($update);
    unset($_SESSION['title']);
    unset($_SESSION['content']);
    @header("location:news-addnew.php?id=$id");
}
}

如何添加一个函数来将图像的缩略图保存在此代码保存原始图像的同一目录中?

4

1 回答 1

0

看看这个链接: http: //www.white-hat-web-design.co.uk/blog/resizing-images-with-php/

这里只是调整大小功能:

function resize($filename, $newfile, $width,$height) { 
    // open the original file
    $image = imagecreatefromjpeg($filename);

    // create a new blank image
    $new_image = imagecreatetruecolor($width, $height); 

    // copy the original, according to the specified width and height
    imagecopyresampled($new_image, $image, 0, 0, 0, 0, $width, $height, imagesx($image), imagesy($image)); 

    // save the new file to $newfile
    imagejpeg ($new_image, $newfile); 
} 

该链接中的更多详细信息。您可能应该使用 SimpleImage 类,它比我在这里提供的功能强大得多

于 2013-02-28T11:12:48.357 回答