Ver Mensaje Individual
  #1 (permalink)  
Antiguo 17/01/2014, 22:23
Avatar de alette666
alette666
 
Fecha de Ingreso: febrero-2010
Ubicación: En la luna
Mensajes: 277
Antigüedad: 14 años, 1 mes
Puntos: 5
php no detecta archivo para descargar del servidor

hola Foro, me tope con un problema a ultimo momento para mi pagina de descarga de script. al llamar al archivo "download.php (en la cual se encarga de traerme el archivo zip para q el usuario lo descargue), me arroja el error de "el archivo no existe"; cuando en realidad si existe y esta bien escrito como debe figurar. Paso la data:

descargar.php
Código PHP:
<?php include('head.php')?>
  <!-- CONTENT -->
  <div id="content">
    <?php include('sidebar.php')?>
    <div id="right">
      <div id="welcome">
        <h1>&nbsp;</h1>
        <?php
          
require('admin/config/connect.php');
          
$cargar"SELECT * FROM $tabla1 ORDER BY id DESC LIMIT 1";
          
$respmysql_query($cargar);
          while(
$rowmysql_fetch_array($resp)){
              
$archivo$row['nombre'];
              
$ext$row['extension'];
              
$bytes$row['size'];
              
$release$row['contenido'];
              
$version$row['version'];
             }
             
mysql_close($connect);
             
             function 
bytesToSize($bytes,$precision2){ 
             
$kilobyte 1024
             
$megabyte $kilobyte 1024
             
$gigabyte $megabyte 1024;
             
$terabyte $gigabyte 1024;
             
             if((
$bytes >= 0)&&($bytes $kilobyte)){
                 return 
$bytes ' B';
                 }elseif
                 ((
$bytes >= $kilobyte)&&($bytes $megabyte)){
                     return 
round($bytes $kilobyte,$precision) . ' KB';
                     }elseif
                     ((
$bytes >= $megabyte)&&($bytes $gigabyte)){
                         return 
round($bytes $megabyte$precision) . ' MB';
                         }else{
                             return 
$bytes ' B';
            }
//Fin del If
            
}//Fin del If function
            
$sizebytesToSize($bytes); 
          
?>
          <a href="deposito/download.php?file=<?php echo $archivo.$ext ?>" title="Descargar <?php echo $archivo?>" target="_blank"><img src="images/descargar.gif" width="450" height="150" style="border:none; text-decoration:none;" /></a>        
        <p><strong>ARCHIVO: </strong><span style="font-size:14px;"><?php echo $archivo ?></span></p>     
        <p><strong>VERSIÓN: </strong><span style="font-size:14px;"><?php echo $version ?></span></p>       
        <p><strong>TAMAÑO: </strong><span style="font-size:14px;"><?php echo $size ?></span></p>  
        <p><strong>COMPRESIÓN: </strong><span style="font-size:14px;"><?php echo $ext ?></span></p>  
        <p><strong>RELEASE: </strong><span style="font-size:14px;"><?php echo $release ?></span></p>
                                  
        <div class="clear"></div>
      </div>
      <br/>
      <div id="block_left">
        <h1>Bloque Publicitario!</h1>
        <iframe width="300" height="250" frameborder="0" scrolling="no" allowtransparency="true" src='http://ads-plus.url.ph/ads_plus/ip2c_rand/300x250/random.php' hspace="2" vspace="2" marginheight="1" marginwidth="1"></iframe>
        </div>

      <div id="block_right">
        <h1>Bloque Publicitario!</h1>
        <iframe width="300" height="250" frameborder="0" scrolling="no" allowtransparency="true" src='http://ads-plus.url.ph/ads_plus/ip2c_rand/300x250/random.php' hspace="2" vspace="2" marginheight="1" marginwidth="1"></iframe>
      </div>
      <div class="clear"></div>
    </div>
  </div>
  <div class="clear"></div>
  <!-- CONTENT END -->
<?php include('footer.php')?>
<a href="deposito/download.php?file=<?php echo $archivo.$ext ?>" title="Descargar <?php echo $archivo?>" target="_blank">...</a> es el encargado de llevar el valor por GET hasta "deposito/download.php" q es donde esta alojado el archivo ZIP q deberia descargar.

download.php
Código PHP:
<?php
if (!isset($_GET['file']) || empty($_GET['file'])) {
 exit();
}
$root '';
$file basename($_GET['file']);
$path $root.$file;
$type '';
 
if (
is_file($path)) {
 
$size filesize($path);
 if (
function_exists('mime_content_type')) {
 
$type mime_content_type($path);
 } else if (
function_exists('finfo_file')) {
 
$info finfo_open(FILEINFO_MIME);
 
$type finfo_file($info$path);
 
finfo_close($info);
 }
 if (
$type == '') {
 
$type "application/force-download";
 }
 
// Definir headers
 
header("Content-Type: $type");
 
header("Content-Disposition: attachment; filename=$file");
 
header("Content-Transfer-Encoding: binary");
 
header("Content-Length: " $size);
 
// Descargar archivo
 
readfile($path);
} else {
 die(
"El archivo no existe.");
}
?>
Y este php se encarga de darme el nombre del archivo zip para descargar. En la variable $root="" estaria vacia porque en la misma carpeta se esta ejecutando el archivo php

Aca les dejo mi pagina con el links, le dan a descargar y les pondra q no existe (cuando en realidad si existe)
http://ads-plus.url.ph/descargar.php

Q es lo q puede estar fallando??
__________________
Y Sócrates dijo...Solo sé que no sé nada.
Entiende la filosofía como una búsqueda colectiva basada en el diálogo.