UPLOAD files via php and mysql

Asked

Viewed 236 times

0

I am trying to make a database for personal use that is to upload boleto and then voucher, but I do not know what I am doing wrong because in Mysql there is only a binary file and not the photo or pdf I put.

Banco de Dados e Arquivos

And it also follows code

<?php
require 'banco.php';
    $vencimento = $_POST['vencimento'];
    $empresa = $_POST['empresa'];
    $produto = $_POST['produto'];
    $descricao = $_POST['descricao'];
    $valor = $_POST['valor'];
    $pagamento = $_POST['pagamento'];
    $banco = $_POST['banco'];

    $arq = $_FILES['arq']['name'];
    $com = $_FILES['comp']['name'];
    $pastaboleto = 'Contas/_images/_boletos/';
    $pastacomp = 'Contas/_images/_comprovantes/';
    $nomeboleto = $pastaboleto . $arq;
    $nomecomprovante = $pastacomp . $com;

    $pdo = Banco::conectar();
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sql = "INSERT INTO `indececontas` (`vencimento`, `empresa`, `produto`, `descricao`, `valor`, `pagamento`, `banco`, `arquivo`, `comprovante`) VALUES ('$vencimento', '$empresa', '$produto', '$descricao', '$valor', '$pagamento', '$banco', '$arq', '$com')";
    $q = $pdo->prepare($sql);
    $q->execute(array($vencimento,$empresa,$produto,$descricao,$valor, $pagamento, $banco));
    move_uploaded_file($_FILES['arq']['tmp_name'], $nomeboleto);
    move_uploaded_file($_FILES['comp']['tmp_name'], $nomecomprovante);      
    Banco::desconectar();
    header("Location: index.php");?>

1 answer

0

First, I recommend saving files with some random suffix hash or prefix from timestamps to avoid overwriting or errors. Second, you may have putting the wrong type in the database column.

  • It is in LONGBLOB. In this case, it stores the file path and not the file. But when inserted in phpmyadmin, it stores in binary. Which type should I use to store files?

  • so LONGBLOB is byte type, you want to save a string, switch to scan. so I recommended for a suffix, not to have overwrite when saving in Fs.

  • I switched and he is still only putting the name of the file... The file itself is not sending.

  • ready, now you should check which are the permissions of the folder in which you want to save.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.