我是第一次这样做,所以没有关于它的信息。我需要调整图像大小。
这是我的代码。
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`.`news` (`id`, `category`, `title`, `img`, `short_content`, `content`, `date`, `lang`) VALUES (NULL, '$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>";
}