0

<?php  
 if(isset($_FILES['arquivo'])){
        // informações da imagens
        $imagem = $_FILES['arquivo'];   
        $numArquivo = count(array_filter($imagem['name']));
        // Local de upload
        $pasta = "img/";
        // Permissões de arquivos
        $tipo       = array('image/jpeg', 'image/png');
        $maxsize    = 1024 * 1024 * 10;
        // mensagens
        $msg        = array();
        $errorMsg   = array(
                                1 => 'Arquivos no upload é maior qye o limite definido de upload_max_filesize, por favor reduza suas imagens',
                                2 => 'O arquivo ultrapassa o limite de tamanho em MAX_FILE_SIZE',
                                3 => 'Upload feito parcialmente, e pode conter erros',
                                4 => 'Upload de arquivo não realizado'
                            );

        if($numArquivo <= 0)
                echo 'Selecione uma imagem';
            else{
                for($i = 0; $i < $numArquivo; $i++){
                    $name = $imagem['name'][$i];
                    $type = $imagem['type'][$i];
                    $size = $imagem['size'][$i];
                    $error = $imagem['error'][$i];
                    $tmp = $imagem['tmp_name'][$i];

                    $extensao = @end(explode('.', $name));
                    $nomes[]=$nomeUnico = rand().".$extensao";

                    if($error != 0)
                        $msg[] = "<b>$name :</b> ".$errorMsg[$error];
                    else if(!in_array($type, $tipo))
                        $msg[] = "<b>$name :</b> Erro tipo imagem não permitida!";
                    else if($size > $maxsize)
                        $msg[] = "<b>$name :</b> Tamanho do(s) arquivo(s) maior que o limite 10MB!";
                    else {
                        if(move_uploaded_file($tmp, $pasta."/".$nomeUnico))
                            $msg[] = "<b>$name :</b> Upload realizado com sucesso!";
                        else
                            $msg[] = "<b>$name :</b> Erro! Ocorreu um erro, tente novamente!";
                        }
                }
                    $nomeimagem = implode(',', $nomes);
                    
                    $result_produtos = "INSERT INTO arquivos (Arquivo) VALUES ('{$nomeimagem}')";
                    $resultado_produtos = mysqli_query($connect, $result_produtos);                        
 // fecha else

Dear, I am uploading images through a code that can be downloaded from the internet, I would like to know if it would be possible to insert the image path to the database, because that way it would be easier for me to pull the data to generate a library.

In short: Need that instead of the name be xxxx.jpg, stay img / xxx.jpg, remembering that they are multiple uploads for a single field in my database. I need you to stay img / xxx.jpg, img / aaaa.jpg

  • .. or https://es.stackoverflow.com – Jens Jan 22 '20 at 16:01
  • 1
    *"I would like to know if it would be possible to insert the image path to the database"* - Yes, it is possible to store data in a database. When you try, in what way does your attempt not work as expected? *"they are multiple uploads for a single field in my database"* - This is a famously bad idea. Keep your relational data relational. If a record can have multiple values, create another table with a foreign key back to that record and add many records to that new table. – David Jan 22 '20 at 16:05

0 Answers0