PHP - error en formato imagen al descargar de servidor

 
Vista:
sin imagen de perfil

error en formato imagen al descargar de servidor

Publicado por Hugo (37 intervenciones) el 04/02/2023 05:45:42
Hola, buenas noches.

Tengo el siguiente problema que no puedo resolver.
A través de un link de descarga, estoy descargando del servidor archivos en formato pdf y archivos de imagen en formato jpg.
Los archivos de formato pdf no han tenido problema, pues se pueden abrir y visualizar, sin embargo los archivos de formato jpg no puedo hacerlo, ya que me dice que el formato de archivo no es compatible.

Si alguien me puede ayudar a resolverlo lo agradezco.

Copio el código:

descarga_comp.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
<?php
include 'archivos_a_descargar.php';
?>
 
<html>
<head>
  <meta charset="utf-8" />
  <title>Descarga Comprobantes</title>
</head>
<body>
 
<table>
<thead>
    <th>id_comp</th>
    <th>ruta</th>
</thead>
<tbody>
  <?php
	foreach ($files as $file):
  ?>
    <tr>
      <td><?php echo $file['id_comp']; ?></td>
      <td><?php echo $file['ruta']; ?></td>
      <td><a href="descarga_comp.php?file_id=<?php echo $file['id_comp'] ?>">Download</a></td>
    </tr>
  <?php
        endforeach;
   ?>
 
</tbody>
</table>

archivos_a_descargar.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
<?php
include ("../Conexion/conexion.php");
 
$sql = "SELECT * FROM comprobantes";
$result = mysqli_query($conexion, $sql);
 
$files = mysqli_fetch_all($result, MYSQLI_ASSOC);
 
// Downloads files
if (isset($_GET['file_id'])) {
    $id = $_GET['file_id'];
 
    // fetch file to download from database
    $sql = "SELECT * FROM comprobantes WHERE id_comp=$id";
    $result = mysqli_query($conexion, $sql);
 
    $file = mysqli_fetch_assoc($result);
    $filepath = $file['ruta'];
 
	echo $filepath;
    if (file_exists($filepath)) {
   		header('Content-Type: application/octet-stream');
		header('Content-Transfer-Encoding: Binary');
		header('Content-Disposition: attachment; filename=' . basename($filepath));
        readfile($file['ruta']);
 
    }
 
}
?>
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