
error al descargar archivo de imagen del servidor
Publicado por Hugo (37 intervenciones) el 05/02/2023 05:29:58
Hola a todos.
Estoy teniendo problemas con la descarga de archivos de imagen o pdf, ya que en el servidor local me anda perfectamente, pero cuando lo subo al hosting no funciona y no entiendo el porqué.
Lo que sucede es que no descarga el archivo y muestra una página con símbolos.
Lo que hago es obtener la ruta almacenada en la bd y con esa ruta fuerzo la descarga.
Copio el código y la imágen del error.
Agradezco mucho si alguien me puede ayudar a resolverlo.
consulta_lic_espec
archivos_a_descargar:
Estoy teniendo problemas con la descarga de archivos de imagen o pdf, ya que en el servidor local me anda perfectamente, pero cuando lo subo al hosting no funciona y no entiendo el porqué.
Lo que sucede es que no descarga el archivo y muestra una página con símbolos.
Lo que hago es obtener la ruta almacenada en la bd y con esa ruta fuerzo la descarga.
Copio el código y la imágen del error.
Agradezco mucho si alguien me puede ayudar a resolverlo.
consulta_lic_espec
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?php
session_start();
?>
<html>
<head>
<title>Intranet</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="stylesheet" type="text/css" href="../Cabecera/cabecera.css">
<link rel="stylesheet" type="text/css" href="../Cabecera/gsa.css">
<link rel="stylesheet" type="text/css" href="consulta_lic_espec.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Kaisei+HarunoUmi:wght@500&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/6.11.0/sweetalert2.css"/>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/6.11.0/sweetalert2.js"></script>
</head>
<body>
<?php
include ("../Conexion/conexion.php");
include ("../Cabecera/cabecera.php");
?>
<?php
require ("../Login/iniciar_session.php");
?>
<div id="Contenedor">
<div id="formulario">
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post" class="form">
<div class="formulario">
<h2 class="titulo">Consulta Licencias Especiales</h2><br><br>
<span class="Desde">Desde:
<input type="date" name="desde" class="fecha" required/></span>
<span class="Hasta">Hasta:
<input type="date" name="hasta" class="fecha" required/></span>
<span class="tipo_lic">Tipo de Licencia:</span><select name="tipo" class="tipo">
<option>Todas</option>
<option>Cita Judicial</option>
<option>Donacion de sangre</option>
<option>Fallecimiento</option>
<option>Hijo discapacitado</option>
<option>Internacion</option>
<option>Matrimonio</option>
<option>PAP-MAMO</option>
<option>Licencia por Congreso</option>
<option>Licencia por Estudio</option>
<option>Violencia de genero</option>
</select>
<span class="estado_lic">Estado:</span><select name="estado" class="estado">
<option>Todos</option>
<option>Autorizado</option>
<option>Denegado</option>
<option>Pendiente</option>
<option>Anulado</option>
</select>
<button type="submit" name="ver" class="btn btn-primary btn boton">Visualizar</button></span>
<a href="gestion_rrhh.php"><button type="button" class="btn btn-danger btn volver">Volver</button></a>
</div>
</form>
<?php
//error_reporting(E_ERROR | E_WARNING | E_PARSE);
date_default_timezone_set("America/Montevideo");
if(isset($_POST['ver'])){
$desde=$_POST['desde'];
$hasta=$_POST['hasta'];
$tipo=$_POST['tipo'];
$estado=$_POST['estado'];
if($tipo=='Todas' && $estado=='Todos'){
$datos="SELECT * FROM licespec WHERE (fechaDesde>='$desde' && fechaDesde<='$hasta') ORDER BY fechaDesde DESC";
$query_datos=$conexion->query($datos);
}
if($tipo=='Todas' && $estado!=='Todos'){
$datos="SELECT * FROM licespec WHERE (fechaDesde>='$desde' && fechaDesde<='$hasta') && estado='$estado' ORDER BY fechaDesde DESC";
$query_datos=$conexion->query($datos);
}
if($tipo!=='Todas' && $estado=='Todos'){
$datos="SELECT * FROM licespec WHERE (fechaDesde>='$desde' && fechaDesde<='$hasta') && tipoLic='$tipo' ORDER BY fechaDesde DESC";
$query_datos=$conexion->query($datos);
}
if($tipo!=='Todas' && $estado!=='Todos'){
$datos="SELECT * FROM licespec WHERE (fechaDesde>='$desde' && fechaDesde<='$hasta') && tipoLic='$tipo' && estado='$estado' ORDER BY fechaDesde DESC";
$query_datos=$conexion->query($datos);
}
if($query_datos==NULL){
echo "<script>
function alerta(){
swal({
title: 'Ups...!',
text: 'No existen registros para el período seleccionado',
type: 'info',
}).then(function(){
window.location='consulta_lic_espec.php';
});
}
alerta();
</script>";
exit();
}
?>
<div class="col-md-8-sm">
<br><table class="table table-striped table-responsive table-sm table-hover table-bordered">
<thead class="encabezado" >
<tr>
<th>N° Solic.</th>
<th>N° Func.</th>
<th>Nombre</th>
<th>Apellido</th>
<th>Sección</th>
<th>Licencia</th>
<th>Descripción</th>
<th>Desde</th>
<th>Hasta</th>
<th>Cant. de Días</th>
<th>Fecha de Solicitud</th>
<th>Estado</th>
<th>Fecha de Autorización</th>
<th>Comprobante</th>
</tr>
</thead>
<tbody>
<?php
while($array_datos=$query_datos->fetch_assoc()){
$fecha_desde=$array_datos['fechaDesde'];
$desde=strtotime($fecha_desde);
$f_desde=date('d-m-Y',$desde);
$fecha_hasta=$array_datos['fechaHasta'];
$hasta=strtotime($fecha_hasta);
$f_hasta=date('d-m-Y',$hasta);
$fecha_solicitud=$array_datos['fechaSolicitud'];
$solic=strtotime($fecha_solicitud);
$f_solic=date('d-m-Y',$solic);
$fecha_autorizacion=$array_datos['fechaAutorizacion'];
$autoric=strtotime($fecha_autorizacion);
$f_autoric=date('d-m-Y',$autoric);
?>
<tr>
<td><?php echo $array_datos['idSolic']?></td>
<td><?php echo $array_datos['numFunc']?></td>
<td><?php echo $array_datos['nombre']?></td>
<td><?php echo $array_datos['apellido']?></td>
<td><?php echo $array_datos['seccion']?></td>
<td><?php echo $array_datos['tipoLic']?></td>
<td><?php echo $array_datos['descripcion']?></td>
<td><?php echo $f_desde?></td>
<td><?php echo $f_hasta?></td>
<td><?php echo $array_datos['cantDias']?></td>
<td><?php echo $f_solic?></td>
<?php
if($array_datos['estado']=='Autorizado'){
echo '<th style="background-color:#AEFE8B">'.$array_datos['estado']. '</th>';
}
if($array_datos['estado']=='Pendiente'){
echo '<th style="background-color:#FFFC4E">'.$array_datos['estado']. '</th>';
}
if($array_datos['estado']=='Denegado'){
echo '<th style="background-color:#FF6C73">'.$array_datos['estado']. '</th>';
}
if($array_datos['estado']=='Anulado'){
echo '<th style="background-color:#CACACA">'.$array_datos['estado']. '</th>';
}
?>
<td>
<?php
if($array_datos['fechaAutorizacion']==NULL){
echo '';
}else{
echo $f_autoric;
}
?></td>
<td>
<?php
$ruta_comp=$array_datos['idSolic'];
if($array_datos['ruta']==NULL){
echo '';
}else{
?>
<a href="archivos_a_descargar.php?file_id=<?php echo $ruta_comp ?>">Descargar</a></td>
<?php
}
?>
</tr>
<?php
}
?>
</tbody>
</table>
<?php
}
?>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</div>
</div>
</body>
</html>
archivos_a_descargar:
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
<?php
session_start();
?>
<?php
include ("../Conexion/conexion.php");
$sql = "SELECT * FROM licespec";
$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 licespec WHERE idSolic=$id";
$result = mysqli_query($conexion, $sql);
$file = mysqli_fetch_assoc($result);
$filepath = $file['ruta'];
if (file_exists($filepath)) {
header('Content-Description: File Transfer');
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Content-Type: application/octet-stream');
header('Content-Transfer-Encoding: Binary');
header('Content-Disposition: attachment; filename=' . basename($filepath));
ob_clean();
flush();
readfile($file['ruta']);
}
}
?>
- error_descargar_imagen.zip(348,4 KB)
Valora esta pregunta


0