Sending an image from one page to another (Codeigniter)

Asked

Viewed 40 times

0

I have a gallery of images loaded dynamically, where the user searches for the category and the system loads the relative images. Below each of the uploaded images has a button, which when clicked, the image referring to the button should be displayed in a div on the new page.

Picture of the Buttons I referred to: inserir a descrição da imagem aqui

My question is how to do this.

VIEW where the gallery with the images is loaded:

<div class="container-galeria row d-flex justify-content-center">
                <?php foreach ($listagem as $foto) : ?>
                    <div class="card mx-3 my-3" style="width: 18rem;">
                        <img class="card-img-top" src="<?php echo base_url(); ?>assets/upload/<?= $foto['caminhoImagem']?>" alt="<?= $foto['tituloImagem']?>">
                        <div class="card-body">
                            <h5 class="card-title"><?= $foto['tituloImagem']?></h5>
                            <p class="card-text"><?= $foto['dscImagem']?></p>
                            <a href="" target="_blank" class="btn btn-primary">icone aqui</a>
                        </div>
                    </div>
                <?php endforeach ?>
            </div>

VIEW where the image will be displayed on the new page:

<div class="area-imagem">
    <img src="" alt="">
</div>

1 answer

0

With the class FTP of codeigniter configure the second connection of the database to just after inserting, editing or deleting the data, php saves the file to the hosting in a temporary folder and runs the following script:

  $caminho_temp= "Arquivos/TEMP/DE/{$this->input->post('numero')}_{$this->input->post('ano')}{$arquivo['file_ext']}";

  $source = $caminho_temp;
    $this->load->library('ftp');
    //FTP configuration
    $ftp_config['hostname'] = '###.150.##.123';
    $ftp_config['username'] = '@@@@@@';
    $ftp_config['password'] = '@@@@@@';
    $ftp_config['debug']    = FALSE;

    //Connect to the remote server
    if($this->ftp->connect($ftp_config) == TRUE){

      //File upload path of remote server
      $destino = "/Arquivos/DE/{$fileName}{$arquivo['file_ext']}";
      $destino_url = "Arquivos/DE/{$fileName}{$arquivo['file_ext']}";

      //Upload file to the remote server
      $this->ftp->upload($source, ".".$destino);

      //Close FTP connection
      $this->ftp->close();
      @unlink($source);
    }else{
      $this->session->set_flashdata('error','Problema de conexão com o servidor de documentos.');
      @unlink($source);
      redirect(base_url()."admin/atos/de/editar/".$this->input->post('id'));
    }

After sending by FTP delete the file from the temporary folder in the hosting or in case of failed sending also delete it.

Process can get a little slow for files larger than 5mb.

Browser other questions tagged

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