1
if I use multpart/form-data in the FORM tag I can save the file but it does not save the file name in the database but if I take the Multipart/form-data does not send the file but saved in the database, how can I fix it?
<input type="file" class="form-control mr-3 my-3" name="arquivo1" id="imageSlideInput1" placeholder="Imagem do Slide" />
<?php
    require '../conexao_banco.php';
// verifica se foi enviado um arquivo 
if(isset($_FILES["arquivo1"]) && $_FILES["arquivo1"]["error"] == 0)
{
    $arquivo_tmp = $_FILES["arquivo1"]["tmp_name"];
    $nome = $_FILES["arquivo1"]["name"];
    // Pega a extensao
    $extensao = strrchr($nome, '.');
    // Converte a extensao para mimusculo
    $extensao = strtolower($extensao);
    // Somente imagens, .jpg;.jpeg;.gif;.png
    // Aqui eu enfilero as extesões permitidas e separo por ';'
    // Isso server apenas para eu poder pesquisar dentro desta String
    if(strstr('.jpg;.jpeg;.gif;.png', $extensao))
    {
        // Cria um nome único para esta imagem
        // Evita que duplique as imagens no servidor.
        $novoNome = md5(microtime()) . '.' . $extensao;
        // Concatena a pasta com o nome
        $destino = '../img_usuario_tema_1/' . $novoNome;  
        // tenta mover o arquivo para o destino
        if( @move_uploaded_file( $arquivo_tmp, $destino  ))
        {
        }}
}
try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    // prepare sql and bind parameters
    $stmt = $conn->prepare("INSERT INTO conte_site_1 (cont_nav_1, titulo_slide_1, texto_slide_1, titulo_slide_2, texto_slide_2, titulo_slide_3, texto_slide_3, titulo_acima_slide, titulo_menu_suspenso_1, texto_menu_suspenso_1, titulo_menu_suspenso_2, texto_menu_suspenso_2, titulo_menu_suspenso_3, texto_menu_suspenso_3, id_usuario, arquivo1) VALUES (:cont_nav_1, :titulo_slide_1, :texto_slide_1, :titulo_slide_2, :texto_slide_2, :titulo_slide_3, :texto_slide_3, :titulo_acima_slide, :titulo_menu_suspenso_1, :texto_menu_suspenso_1, :titulo_menu_suspenso_2, :texto_menu_suspenso_2, :titulo_menu_suspenso_3, :texto_menu_suspenso_3, :id_usuario, :arquivo1) ");
        $stmt->bindParam(':cont_nav_1', $_POST['cont_nav_1']);
        $stmt->bindParam(':titulo_slide_1', $_POST['titulo_slide_1']);
        $stmt->bindParam(':texto_slide_1', $_POST['texto_slide_1']);
        $stmt->bindParam(':titulo_slide_2', $_POST['titulo_slide_2']);
        $stmt->bindParam(':texto_slide_2', $_POST['texto_slide_2']);
        $stmt->bindParam(':titulo_slide_3', $_POST['titulo_slide_3']);
        $stmt->bindParam(':texto_slide_3', $_POST['texto_slide_3']);
        $stmt->bindParam(':titulo_acima_slide', $_POST['titulo_acima_slide']);
        $stmt->bindParam(':titulo_menu_suspenso_1', $_POST['titulo_menu_suspenso_1']);
        $stmt->bindParam(':texto_menu_suspenso_1', $_POST['texto_menu_suspenso_1']);
        $stmt->bindParam(':titulo_menu_suspenso_2', $_POST['titulo_menu_suspenso_2']);
        $stmt->bindParam(':texto_menu_suspenso_2', $_POST['texto_menu_suspenso_2']);
        $stmt->bindParam(':titulo_menu_suspenso_3', $_POST['titulo_menu_suspenso_3']);
        $stmt->bindParam(':texto_menu_suspenso_3', $_POST['texto_menu_suspenso_3']);
        $stmt->bindParam(':id_usuario', $_POST['id_usuario']);
        $stmt->bindParam(":arquivo1", $_POST["arquivo1"]);
        $stmt->execute();
        echo '<script type="text/javascript"> alert("Site Criado Com Sucesso,"); self.location.href="pag_user.php";</script>'; 
    }
catch(PDOException $e)
    {
    echo "Ops... Erro no servidor: ".$e->getMessage();
    }
?>
what do you want to fix? I don’t quite understand
– Wees Smith
well when I use Multipart/form-data I can send the image to the folder but do not save the information in the database
$stmt->bindParam(":arquivo1", $_POST["arquivo1"]);and if I take the Multipart/form-date does not send the image to the folder but saves the information , I would like to do to work both– Nycolas
because when you use Multipart/form-data it is no longer $_POST but $_FILES, in case it would be $_FILES["archive1"]["name"] or $_FILES["archive1"]["tmp_name"] which is the temporary file
– Wees Smith
https://www.php.net/manual/en/features.file-upload.post-method.php
– Wees Smith
good now of Column error 'cont_nav_1' cannot be null
– Nycolas
well I was able to send now when saving the information in the database, Save array would like to save the file name
– Nycolas
Let’s go continue this discussion in chat.
– Nycolas