Hi, I was able to run the code and save the file, but I want you to save only images. Without the filter it saves any kind of file. How could it make only the jpg, jpeg and png extensions be saved? Below the code
<form action="proc_artigos.php" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="">Título</label>
<input class="form-control" type="text" name="titulo" required>
</div>
<div class="form-group">
<label for="">Imagem</label>
<input type="file" name="imgUpload">
</div>
<div class="form-group">
<label for="">Conteúdo</label>
<textarea class="form-control" type="text" name="texto" rows="30" required ></textarea>
</div>
<input name="send" class="btn btn-primary btn-block" type="submit" value="Salvar">
</form>
File php:
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$file = $_FILES["imgUpload"];
if ($file["error"]) {
throw new Exception("Error: " . $file["error"]);
}
$dirUploads = "uploads";
if (!is_dir($dirUploads)) {
mkdir($dirUploads);
}
if (move_uploaded_file($file["tmp_name"], $dirUploads . DIRECTORY_SEPARATOR . $file["name"])) {
} else {
throw new Exception("Não foi possível salvar o arquivo.");
}
}
Thank you! Note: The rest is working, I just want to limit the extensions of the files that can be saved.