3
I created a database called Form
and table with the following information
contatos (id int A.I, nome varchar(30), idade int(2), foto(blob)
I made that standard form:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<form name="CadastroAlunos" type="text" method="post" enctype="multipart/form-data" action="upload.php">
Nome: <input type="text" name="NomeAluno"></br>
Idade: <input type="text" name="IdadeAluno"></br>
Foto: <input type="file" name="image" /></br>
<input type="submit" value="Enviar" name="envia" />
</form>
</body>
</html>
UPLOAD.PHP
<?php
include_once 'conexao.php';
$nome = $_POST['NomeAluno'];
$idade = $_POST['IdadeAluno'];
$foto = $_FILES['image'];
move_uploaded_file ( string $foto , string $novoDestino );
$sql = "INSERT INTO contatos (nome, idade, foto) values ('$nome', '$idade', $novoDestino");
?>
How do I record the photo along with more form information?
Use
$_FILES
to manipulate the file,$_POST
for form information and move_uploaded_file to transfer the file to the server.– rray
I understood what you said, only I’m having trouble implementing. I had seen some codes before, only the person uploaded the photo to a folder on the computer. I want it to go to the database. I will edit my question and add the php I made. If you can take a look
– WSS
You need to take the contents of the file with file_get_contents this will return a 'string' then just record in the database. You can do a test and print the return of
file_get_contents()
.– rray
I recommend saving the image in a folder and in your database you record the path to the file, saving the file itself in the database is not one of the best practices because your database may get overloaded and start to slow down.
– RFL
Related: It is wrong to write byte of images in the database?
– rray
@rray I will see to it right now.
– WSS
@Rafaelacioly then, in this regard I do not need to worry so much, because this project is academic, I will upload.
– WSS