0
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 type of file. How could I make only jpg, jpeg and png extensions be saved? Below Cod.
<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>
Php file:
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 file extensions that can be saved.
I used to, but I forgot.
– Vinicius De Jesus
I was wrong. No point...
– Andrei Coelho
You can change the MIME type too! That is, it doesn’t change anything. =/
– Andrei Coelho