Good morning!
I'm trying to upload a loaded image via an input "type = file", convert the image to a BLOB and store it in my BD MySql.
However, I'm having difficulty receiving the image that was sent by $ POST.
Here is my view structure:
<form action="/upload.php" method="post" enctype="multipart/form-data">
<div class="file-upload">
<div class="image-upload-wrap">
<input class="file-upload-input" type='file' name="minhaImagem" onchange="readURL(this);" accept="image/*" />
<div class="drag-text">
<h3>Arraste ou selecione uma imagem</h3>
</div>
</div>
<div class="file-upload-content">
<img class="file-upload-image" src="#" alt="Sua Imagem"/>
<div class="image-title-wrap">
<button type="button" onclick="removeUpload()" class="remove-image">Remover <span class="image-title">Imagem Selecionada</span></button>
</div>
</div>
</div>
<input type="submit" value="Salvar"/>
</form>
In the file upload.php, I tried to make a vardump on a variable that gets the result of file_get_contents, but it returns an error.
$imgData = addslashes(file_get_contents($_FILES['minhaImagem']['tmp_name']));
vardump($imgData);
Error : Warning: file_get_contents (): Filename can not be empty in C: \ xampp \ htdocs \ upload.php string (0)
I would like to know if there is any problem in the structure of my submit or is there any other way to do this.
EDIT:
When doing a "vardump ($ _ FILES)" in my upload.php, it returns me the image data normally:
array(1) { ["imagem"]=> array(5) { ["name"]=> string(15) "wallpaper-6.png" ["type"]=> string(9) "image/png" ["tmp_name"]=> string(23) "C:\xampp\tmp\php5A2.tmp" ["error"]=> int(0) ["size"]=> int(2961775) } }
Note: I checked in php.ini and "upload_max_filesize" is large enough for the image I want to upload.
Thank you.