这是我的代码(将新闻添加到数据库中)。
if(!empty($_FILES['img']['name'])){
$extension = end(explode(".",$_FILES['img']['name']));
$name = $_FILES['img']['name'];
$size = $_FILES['img']['size'];
if(file_exists("views/admin/uploads/".$name)){
$errors[] = "File with this name already exists!";
}
if($extension != "jpg" && $extension != "png" && $extension != "gif" && $extension != "JPG"){
$errors[] = "Unknown file format!";
}
}
if(count($errors)==0){
$query = mysql_query("INSERT INTO `avetisyan`.`$category` (`id`, `category`, `sub_category`, `news_category`, `title`, `img`, `short_content`, `content`, `date`, `lang`) VALUES (NULL, '$category', '$sub_category', '$news_category', '$title', '$name', '$short_content', '$long_content', '$date', '$lang')");
move_uploaded_file($_FILES['img']['tmp_name'],"views/admin/uploads/".$name);
echo "<h2 align=\"center\">Successfully added!</h2>";
}
else{
print "<h3>Errors!</h3><ul><li>".join("</li><li>",$errors)."</li></ul>";
}
如您所见,图像的名称进入数据库,图像进入 /views/admin/uploads/..
在新闻中显示此图像的正确方法是什么?如何?