function move_uploaded_file

Asked

Viewed 165 times

1

I’m having difficulty to do multiple uploads,in the move_uploaded_file command it’s only sending one.

   foreach ($imagem['name'] as $key => $fotos) {

                    if (isset($tipoAlbum)) {

                      $dados->setAlbum($tipoAlbum);

                          if (!file_exists($tipoAlbum)) {

                              @mkdir("album/" . $dados->getAlbum());

                                 echo $imagem['tmp_name'][$key];
                                echo $fotos; 
                              $t = $imagem['tmp_name'][$key];


                              move_uploaded_file($t, "album/" . $dados->getAlbum() . "/" . $dados->getImagem());

                          }

                    }

            } 

Can someone give me a hint?

  • What are all these variables? Where does it come from and how is it defined $dados? Are you taking care that every image has a unique name? Because if the name does not vary, the files will be overwritten and only the last one will exist.

  • $data is an object of the other class that only serves to Insert,select and also has get and set as extends and great tip I will put to not overwrite...

1 answer

1

I managed to solve the problem follow the code below

 // Busca os dados para o envio da imagem ao servidor.
      for ($i = 0; $i < count($imagem['name']); $i++) { 

        // Verifica se o arquivo já existe no servidor.
        if (!file_exists("album/".$dados->getAlbum()."/".$imagem['name'][$i])) {
    // o mkdir coloquei em outro lugar          
          // Move para o servidor
            move_uploaded_file($imagem['tmp_name'][$i], "album/".$dados->getAlbum()."/".$imagem['name'][$i]); 

        }

      }
  • The problem, then, was the conflict of names?

  • That’s right, like you said, he was copying the names of the images and just sending a file

Browser other questions tagged

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