PHP - descargar archivo con php - mysql

 
Vista:
Imágen de perfil de Orlando
Val: 103
Ha disminuido 1 puesto en PHP (en relación al último mes)
Gráfica de PHP

descargar archivo con php - mysql

Publicado por Orlando (73 intervenciones) el 15/10/2016 19:25:27
Muy buenos día y muchas gracias de antemano.

Llevo varios días buscando info para tratar de descargar los archivos que tengo direccionado en mi base de datos como muestra la figura que anexo, pero nada, hasta ahora no me han funcionado los ejemplo, ahora bien puedo mostrar los archivos en pantalla pero quisiera descargarlo, alguien me puede ayudar con un tutorial o con un código para hacerlo?

Gracias nuevamente.

Este son los códigos, si alguien lo necesita puede tomarlo, corre perfectamente :

INDEX.PHP:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<?php
include_once 'config.inc.php';
if (isset($_POST['subir'])) {
    $nombre = $_FILES['archivo']['name'];
    $tipo = $_FILES['archivo']['type'];
    $tamanio = $_FILES['archivo']['size'];
    $ruta = $_FILES['archivo']['tmp_name'];
    $destino = "archivos/" . $nombre;
    if ($nombre != "") {
        if (copy($ruta, $destino)) {
            $titulo= $_POST['titulo'];
            $descri= $_POST['descripcion'];
            $db=new Conect_MySql();
            $sql = "INSERT INTO tbl_documentos(titulo,descripcion,tamanio,tipo,nombre_archivo) VALUES('$titulo','$descri','$tamanio','$tipo','$nombre')";
            $query = $db->execute($sql);
            if($query){
                echo "Se guardo correctamente";
            }
        } else {
            echo "Error";
        }
    }
}
?>
 
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <div style="width: 500px;margin: auto;border: 1px solid blue;padding: 30px;">
            <h4>Subir PDF</h4>
            <form method="post" action="" enctype="multipart/form-data">
                <table>
                    <tr>
                        <td><label>Titulo</label></td>
                        <td><input type="text" name="titulo"></td>
                    </tr>
                    <tr>
                        <td><label>Descripcion</label></td>
                        <td><textarea name="descripcion"></textarea></td>
                    </tr>
                    <tr>
                        <td colspan="2"><input type="file" name="archivo"></td>
                    <tr>
                        <td><input type="submit" value="subir" name="subir"></td>
                        <td><a href="lista.php">lista</a></td>
                    </tr>
                </table>
            </form>
        </div>
    </body>
</html>

LISTA.PHP:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <table>
            <tr>
                <td>titulo</td>
                <td>descripcion</td>
                <td>tamanio</td>
                <td>tipo</td>
                <td>nombre</td>
            </tr>
        <?php
        include 'config.inc.php';
        $db=new Conect_MySql();
            $sql = "select*from tbl_documentos";
            $query = $db->execute($sql);
            while($datos=$db->fetch_row($query)){?>
            <tr>
                <td><?php echo $datos['titulo']; ?></td>
                <td><?php echo $datos['descripcion']; ?></td>
                <td><?php echo $datos['tamanio']; ?></td>
                <td><?php echo $datos['tipo']; ?></td>
                <td><a href="archivo.php?id=<?php echo $datos['Id_documento']?>"><?php echo $datos['nombre_archivo']; ?></a></td>
                <td></td>
 
            </tr>
 
          <?php  } ?>
 
        </table>
    </body>
</html>

ARCHIVO.PHP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        include 'config.inc.php';
        $db=new Conect_MySql();
            $sql = "select * from tbl_documentos where Id_documento=".$_GET['id'];
            $query = $db->execute($sql);
            if($datos=$db->fetch_row($query)){
                if($datos['nombre_archivo']==""){?>
        <p>NO tiene archivos</p>
                <?php }else{ ?>
        <iframe src="archivos/<?php echo $datos['nombre_archivo']; ?>"></iframe>
 
                <?php } } ?>
    </body>
</html>

config.inc.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
 
class Conect_MySql {
     var $obj = array ( "dbname"	=>	"XXXXXXXX",
                       "dbuser"		=>	"XXXXXXX"		,
                       "dbpwd"		=>	"XXXXXXXXX",
                       "dbhost"		=>	"XXXXXXXX"	);
 
 
     var $q_id	="";
     var $ExeBit	="";
     var $db_connect_id = "";
     var $query_count   = 0;
    private function connect(){
		$this->db_connect_id = mysqli_connect($this->obj['dbhost'],$this->obj['dbuser'],$this->obj['dbpwd'],$this->obj['dbname']);
             if (!$this->db_connect_id)
              {
                echo (" Error no se puede conectar al servidor:".mysqli_connect_error());
    	  }
  }
 
function execute($query) {
        $this->q_id = mysqli_query($this->db_connect_id,$query);
        if(!$this->q_id ) {
            $error1 = mysqli_error($this->db_connect_id);
            die ("ERROR: error DB.<br> No Se Puede Ejecutar La Consulta:<br> $query <br>MySql Tipo De Error: $error1");
            exit;
        }
	$this->query_count++;
	return $this->q_id;
    }
 
 
  public function fetch_row($q_id = "") {
    	if ($q_id == "") {
    		$q_id = $this->q_id;
   	 	}
        $result = mysqli_fetch_array($q_id);
        return $result;
    }
 
 public function get_num_rows() {
        return mysqli_num_rows($this->q_id);
    }
 
public function get_row_affected(){
    return mysqli_affected_rows($this->db_connect_id);
}
 
public	function get_insert_id() {
    return mysqli_insert_id($this->db_connect_id);
}
 
public  function free_result($q_id) {
   		if($q_id == ""){
    		$q_id = $this->q_id;
		}
	mysqli_free_result($q_id);
    }
 
public function close_db(){
        return mysqli_close($this->db_connect_id);
    }
 
public function more_result() {
		return mysqli_more_results($this->db_connect_id);
	}
public function next_result() {
		return mysqli_next_result($this->db_connect_id);
	}
 
  public function __construct(){
        $this->connect();
    }
 
}
?>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

descargar archivo con php - mysql

Publicado por Francisco (1 intervención) el 02/11/2016 04:01:58
Amigo me urge sabe como poner los acentos en la conexión con esta programación, en la parte de la conexión ya que no la veo por ningun lado


1
2
3
4
5
6
private function connect(){
	$this->db_connect_id = mysqli_connect($this->obj['dbhost'],$this->obj['dbuser'],$this->obj['dbpwd'],$this->obj['dbname']);
	if (!$this->db_connect_id)
	{
		echo (" Error no se puede conectar al servidor:".mysqli_connect_error());
	}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar