获取提交的图片
$file_logo = $_FILES['img_logo'];
if($file_logo["error"] == 0){
$file_type=array("image/jpeg","image/pjpeg","image/gif","image/png","image/x-png");
打印图片的详细信息
// var_dump($file_logo['type']);
// exit;
if(in_array($file_logo["type"],$file_type)){
设置提交的图片最大尺寸
$MAX_SIZE=2000000;
if($file_logo["size"] <= $MAX_SIZE){
$new_name = time().mt_rand(10000,9999).strrchr($file_logo['name'],'.');
设置路径
$address = '../images/';
$address1是为了在smarty模板中访问路径而设置
$address1 = '/images/';
移动至相应的文件夹下
move_uploaded_file($file_logo["tmp_name"],$address.$new_name);
收集数据
$title = $_POST['title'];
$shorttext = $_POST['shorttext'];
$img_logo = $address1.$new_name;
$content = $_POST['content'];
添加至数据库
$q = "insert into news(title,news_logo,shorttext,content,time) values('$title','$img_logo','$shorttext','$content',now())";
if(mysql_query($q) > 0){
echo "添加成功.....<br /><br />";
echo '.......<a href="news_desc.php">返回页面</a>';
}
else{
echo "添加失败。。。";
}
}
}
}