PHP Insert image in the bank Mysql Xampp

-1

I'm trying to insert an image into the MySql bank via PHP , actually its path, after moving the picture to a folder in the root. I'm using xampp. All the codes I tested normally insert the other form data but not the image. Does anyone know anything else that should be done? What I want is to register a user and his profile picture. Can you help?

Part of My code (separate files):

Form

<form method="POST" action="cadusuario.php" enctype="multipart/form-data">                                                      
    <label for="nomecompleto">Nome completo:</label>
    <input type="text" name="nomecompleto" id="nomecompleto" placeholder="Digite seu usuario ex. nome.sobrenome" size="50" />
    <br class="block" />
    <label for="nome">Usuario:</label>
    <input type="text" name="nome" id="nome" placeholder="Digite seu usuario ex. nome.sobrenome" size="50" />
    <br class="block" />
    <label for="cpf">CPF:</label>
    <input type="text" name="cpf" id="cpf" placeholder="Digite seu CPF"  size="45" />
    <br class="block" />
    <label for="senha">Senha:</label>
    <input type="password" name="senha" id="senha" placeholder="Digite sua senha de acesso" size="30" />
    <input type="text" name="setor" id="setor"/>
    <br class="block" />
    <label for="avatar">Avatar:</label>
    <input type="file" name="avatar" id="avatar" placeholder="Abrir Foto" />

    <button type="btn" data-icon="plus" data-rel="dialog">Cadastrar</button><p>                                 
</form>

PHP

$nome  =   mysqli_real_escape_string($conn, $_POST['nome']);
$cpf   =  (int) $_POST['cpf'];
$senha =  md5($_POST['senha']);
$nomecompleto = $_POST['nomecompleto']; 
$setor = $_POST['setor'];
$PASTA = "./imagensPHP/";

$imagem = $_FILES["avatar"]["name"];
$temp = $_FILES["avatar"]["tmp_name"];                      

if (!file_exists($PASTA)){
    mkdir("$PASTA", 0700);
}
move_uploaded_file($temp,$PASTA.$imagem);                       
$str_insert = "INSERT INTO 'tb_usuarios' (cpf, nomeusuario, senha, nomecompleto, avatar, setor) 
                VALUES ('".$cpf."','".$nome."','".$senha."','".$nomecompleto."','".$imagem."','".$setor."')";                           
$result = mysqli_query($conn,$str_insert);          
print_r($_FILES['avatar']);
    
asked by anonymous 20.10.2018 / 14:16

1 answer

0

In the image variable, use:

$image = addslashes(file_get_contents($_FILES['file']['tmp_name']));

    
20.10.2018 / 17:49