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");
}
}
我怎麼能增加一個功能保存縮略圖中的圖像這個代碼保存原始圖像的目錄相同嗎?
作爲一個方面說明:'$ _REQUEST ['id']'可以讓你的數據庫變得如此乾淨而空虛,你永遠不會知道什麼命中您。在它前面添加'(int)':'$ id =(int)$ _ REQUEST ['id'];'。對於縮略圖,你必須先嚐試一些東西,或者你希望有人爲你製作代碼? – 2013-02-28 10:58:46
謝謝米海那個筆記,(int)加了。 – user2053021 2013-02-28 11:02:24