0
Good afternoon this is my first post here, so I apologize if I’m repeating a question, let’s go to error have a registration application that I’m trying to implement file upload,below follows the PHP code that is doing the correct function:
<?php
//conectar ao BD.
$conn = mysqli_connect("localhost", "root", "", "gestao-unical");
if($conn) {
//conexao estabelecida.
echo "conectado";
}
//se o botão com o nome SendCadImg foi clicado
if(isset($_POST['SendCadImg'])) {
//declarando as variaveis
$filename = $_FILES['arquivos']['name'];
$filetmpname = $_FILES['arquivos']['tmp_name'];
$idEvento = $_POST['campoIDEVENTO'];
//pasta para onde vai os arquivos
$folder = 'arquivos/';
//função para salvar as imagens carregadas em uma pasta específica
move_uploaded_file($filetmpname, $folder.$filename);
//insert da imagem (nome da imagem) no banco de dados
$sql = "INSERT INTO `uploadedimage` (`imagename`,`idEvento`) VALUES ('$filename','$idEvento')";
$qry = mysqli_query($conn, $sql);
if( $qry) {
echo "</br>image uploaded";
}
}
?>
to list the files use the code below, but without reference to what was written in MYSQL
<?php
$pasta = 'arquivos/';
if(is_dir($pasta))
{
$diretorio = dir($pasta);
while(($arquivo = $diretorio->read()) !== false)
{
echo '<a href='.$pasta.$arquivo.'>'.$arquivo.'</a><br />';
}
$diretorio->close();
}
else
{
echo 'A pasta não existe.';
}
?>
how to take advantage of Insert and list the files by the ID generated in the database?
thanks for the answer , Oce understood what I want to do , I got your code but did not understand the Wile , I tried to use it and does not return anything on the screen.
– Gillen Silva
I’m sorry I tried to replace the
mysqli_fetch_assoc($result)
formysqli_fetch_array($result, MYSQLI_ASSOC)
and do not forget to include the Mysql connection at the beginning of the program. while is to read all records that return in your query, as it can return more than one line– Vinicius Fernandes