Ver Mensaje Individual
  #1 (permalink)  
Antiguo 23/04/2009, 13:04
Lemuriano
 
Fecha de Ingreso: abril-2009
Mensajes: 35
Antigüedad: 15 años
Puntos: 1
Hacer que si un archivo existe ponga el link a este y sino no

Bueno gente, eso... Les comento que no soy programador ni nada por el estilo, simplemente me las ingenio para hacer algunas cositas chicas, o para modificar levemente algunas ya hechas. Por mis propios medios he hecho este codigo php:

Código PHP:
<table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><div align="center"><img src="images/line.png" width="500" height="25" /></div></td>
  </tr>
</table>
<table width="500" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#CFEBEF">
  <tr>
    <td width="80" rowspan="2"><div align="center"><a href="PHOTOS/<? echo str_pad($gal3"0"STR_PAD_LEFT)?>/zips/<? echo str_pad($gal3"0"STR_PAD_LEFT)?>.rar"><img src="images/zip.jpg" width="73" height="60"></div></td>
    <td width="200" height="30" valign="bottom"><div align="left" class="Estilo3">Download Full Photoset</div></td>
    <td width="200" height="30" valign="bottom"><div align="right" class="Estilo3">Download Full Photoset</div></td>
    <td width="80" rowspan="2"><div align="center"><a href="PHOTOS/<? echo str_pad($gal3"0"STR_PAD_LEFT)?>/zips/<? echo str_pad($gal3"0"STR_PAD_LEFT)?>_hi_res.rar"><img src="images/zip.jpg" width="73" height="60"></div></td>
  </tr>
  <tr>
    <td width="200" height="30" valign="top"><div align="left" class="Estilo3">Lo-Res (1024x768)</div></td>
    <td width="200" height="30" valign="top"><div align="right" class="Estilo3">Hi-Res (2560x1920)</div></td>
  </tr>
  <tr>
    <td width="80"><div align="center">
    <? 
    $number 
str_pad($gal3"0"STR_PAD_LEFT)?>
    <? 
    $endfile 
".rar" ;
    
$filename "PHOTOS/$number/zips/$number$endfile" ;
    print  
round(filesize($filename) / 1000000) . " Mb" ?>
    </div></td>
    <td height="30" valign="top">&nbsp;</td>
    <td height="30" valign="top">&nbsp;</td>
    <td width="80"><div align="center">
    <? 
    $number 
str_pad($gal3"0"STR_PAD_LEFT)?>
    <? 
    $endfile2 
"_hi_res.rar" ;
    
$filename2 "PHOTOS/$number/zips/$number$endfile2" ;
    print  
round(filesize($filename2) / 1000000) . " Mb" ?>
    </div></td>
  </tr>
</table>
Esto funciona perfectamente, pero a continuacion me he percatado, de que no siempre existiran dichos archivos que se intentan descargar. Por ello he intentado hacer una comprobacion previa de si el archivo existte, mediante la funcion file_exist, pero aqui es donde viene mi problema, ya que no logro que funcione. A primera vista me parecia algo bastante sencillo (y debe serlo) pero mi escasa o nula experiencia no me permite descubrir porque, este es el nuevo codigo que no funciona:

Código PHP:
<? 
    $number 
str_pad($gal3"0"STR_PAD_LEFT) ;
    
$endfile ".rar" ;
    
$endfile2 "_hi_res.rar" ;
    
$filename "PHOTOS/$number/zips/$number$endfile" ;
    
$filename2 "PHOTOS/$number/zips/$number$endfile2" ?>

<table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><div align="center"><img src="images/line.png" width="500" height="25" /></div></td>
  </tr>
</table>
<table width="500" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#CFEBEF">
  <tr>
    <td width="80" rowspan="2"><div align="center">
    <? 
    
if (file_exists($filename)) 
        print <
a href="$filename"/zips/"$filename$endfile><img src="images/zip.jpg" width="73" height="60"></div></td>" ;
    else print 
"<img src="images/zip.jpg" width="73" height="60"></div></td>" ?>
    <td width="200" height="30" valign="bottom"><div align="left" class="Estilo3">Download Full Photoset</div></td>
    <td width="200" height="30" valign="bottom"><div align="right" class="Estilo3">Download Full Photoset</div></td>
    <td width="80" rowspan="2"><div align="center">
    <? 
    
if (file_exists($filename)) 
        print <
a href="$filename2"/zips/"$filename2$endfile2><img src="images/zip.jpg" width="73" height="60"></div></td>" ;
    else print 
"<img src="images/zip.jpg" width="73" height="60"></div></td>" ?>
  </tr>
  <tr>
    <td width="200" height="30" valign="top"><div align="left" class="Estilo3">Lo-Res (1024x768)</div></td>
    <td width="200" height="30" valign="top"><div align="right" class="Estilo3">Hi-Res (2560x1920)</div></td>
  </tr>
  <tr>
    <td width="80"><div align="center"><? print  round(filesize($filename) / 1000000) . " Mb" ?>
    </div></td>
    <td height="30" valign="top">&nbsp;</td>
    <td height="30" valign="top">&nbsp;</td>
    <td width="80"><div align="center"><? print  round(filesize($filename2) / 1000000) . " Mb" ?>
    </div></td>
  </tr>
</table>
Lo que quiero es en la primer parte, que si el archivo no existe no agregue ningun link a la imagen, y en la segunda parte, donde muestra el tamaño del archivo, si este no existe, en lugar del tamaño mostrar un texto que diga "NO FILE" o "NOT AVAILABLE" o algo asi.

Desde ya muchas gracias por cualquier ayuda que me puedan dar.

Marcelo.