Ir ao conteúdo
  • Cadastre-se

PHP Como faço um link para download de documento dos usuários para o admin?


Posts recomendados

Formulário

<form method="post" action="" id="acc-form" accept-charset="UTF-8" enctype="multipart/form-data">
    <label>
        <?=_('Username')?>: <span class="muted"><?=_('O nome de usuário não pode ser alterado') ?></span>
    </label>
    <input type="text" name="username" value="<?php print htmlspecialchars($user->username); ?>" class="required form-control" readonly="readonly"/>
    
    <br/>
    <label>
        <?=_('E-mail:')?>
    </label>
    <input type="email" name="email" value="<?php print htmlspecialchars($user->email); ?>" class="required form-control" />
    
    <br/>
    
    <label>
        <?=_('Senha:')?> <span class="muted"><?=_('atual ou um novo') ?></span>
    </label>
    <input type="password" name="password" placeholder="****" class="required form-control" />
    
    <br/>
    
    <label>
        <?=_('Foto de Perfil:') ?>
    </label>
    <input type="file" name="file" class="form-control" />
    <br/>


    <label>
        <?=_('CPF:') ?>
    </label>
    <input type="file" name="cpfarq" class="form-control" />
    <br/>

    <label>
        <?=_('RG:') ?>
    </label>
    <input type="file" name="rgarq" class="form-control" />
    <br/>

    <label>
        <?=_('CNH:') ?>
    </label>
    <input type="file" name="cnh" class="form-control" />
    <br/>

    
    <input type="submit" name="sb_signup" value="<?=_('Atualizar') ?>" class="btn btn-info"/>

</form>

 

Eu coloquei um array para enviar os documentos, só n to conseguindo fazer ele mostrar na tabela do admin:

public function index() { $this->checkLoggedIn();

    if ($this->input->post('sb_signup')) {
        if (!$this->input->post('email') OR !$this->input->post('password')) {
            $data['form_message'] = div_class("Email e senha são obrigatórios", 'alert alert-danger');
        } else {

            $this->db->where(["email" => $this->input->post('email', true)]);
            $this->db->where("userID != " . is_user_logged_in());
            $user = $this->db->get("users");

            if (count($user->result())) {
                $data['form_message'] = '<div class="alert alert-warning">';
                $data['form_message'] .= _('Nome de usuário / e-mail em uso, escolha outro.');
                $data['form_message'] .= '</div>';
            } else {

                //profile pic
                if (isset($_FILES['file']) AND $_FILES['file']['error'] == 0) {
                    //make thumbnail
                    $rand = md5(uniqid());
                    $ext = explode(".", $_FILES['file']['name']);
                    $ext = strtolower(end($ext));

                    if (!@getimagesize($_FILES['file']['tmp_name'])) {
                        die(_("Invalid picture"));
                    }

                    $config['image_library'] = 'gd2';
                    #$config['source_image'] = getcwd() .'/uploads/' .  $rand . '.' . $ext;
                    $config['source_image'] = $_FILES['file']['tmp_name'];
                    $config['create_thumb'] = false;
                    $config['maintain_ratio'] = true;
                    $config['width'] = 48;
                    $config['height'] = 48;
                    $config['new_image'] = getcwd() . '/uploads/' . $rand . '.' . $ext;

                    $this->load->library('image_lib', $config);

                    $this->image_lib->resize();

                    if (!$this->image_lib->resize()) {
                        echo $this->image_lib->display_errors();
                    } else {
                        $thephoto = $rand . '.' . $ext;
                        $this->db->where("userID", is_user_logged_in());
                        $this->db->update("users", ['photo' => $thephoto]);
                    }
                }

                $arrayFile = array();
                $arrayFile["cpfarq"]="_cpf";
                $arrayFile["rgarq"]="_rg";
                $arrayFile["cnh"]="_cnh";
                $arrayFile["casamento"]="_casamento";

                foreach( array_keys($arrayFile) as $fileKey) {
                    if (isset($_FILES[$fileKey]) && $_FILES[$fileKey]['error'] == 0) {
                        //$rand = md5(uniqid());
                        $ext = explode(".", $_FILES[$fileKey]['name']);
                        $ext = strtolower(end($ext));
                        $tmpfile = $_FILES[$fileKey]['tmp_name'];

                        $tmpfilename = is_user_logged_in() . $arrayFile[$fileKey] . '.' .$ext; //$rand . '.' . $ext;
                        if(move_uploaded_file($tmpfile, getcwd() . '/uploads/' .$tmpfilename)) {
                            $this->db->where("userID", is_user_logged_in());
                            $this->db->update("users", [$fileKey => $tmpfilename]);
                        }
                    }
                }

 

Tabela do admin:

 <div class="table-responsive">
    <table class="table table-bordered table-striped" id="dataTbl">
        <thead>
            <tr>
                <th>ID</th>
                <th>IP Addr</th>
                <th>Username</th>
                <th>Email</th>
                <th>Sobre</th>
                <th>Ativo</th>
                <th>Remover</th>
                <th>Ação</th>

            </tr>
        </thead>
        <tbody>
            <?php foreach($users as $m) : ?>
            <tr>
                <td><?=$m->userID?></td>
                <td><?=long2ip($m->ip)?></td>
                <td><?=$m->username?></td>
                <td><?=($m->email)?></td>
                <td><?=$m->about?></td>
                <td><a href="/users/approveuser/<?=$m->userID;?>"><?php print($m->ativo ? "Ativo" : "Inativo"); ?></a></td>
                <td><a href="/admin/users/remove/<?=$m->userID;?>"><b class="glyphicon glyphicon-remove"></b></a></td>
                <td>
                    <a href="/admin/users/remove/<?=$m->userID;?>" class="btn btn-xs btn-default" onclick="return confirm('Tem certeza de que deseja ativar/desativar usuário?')">Ativar/Desativar</a>
                </td>
            </tr>

            <?php endforeach; ?>
        </tbody>
    </table>
    </div>

    <?php endif; ?>
</div>

 

Link para o comentário
Compartilhar em outros sites

Crie uma conta ou entre para comentar

Você precisa ser um usuário para fazer um comentário

Criar uma conta

Crie uma nova conta em nossa comunidade. É fácil!

Crie uma nova conta

Entrar

Já tem uma conta? Faça o login.

Entrar agora

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

Ebook grátis: Aprenda a ler resistores e capacitores!

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!