4
I need a PHP script that checks if a file exists in a folder, if it doesn’t exist it checks in the next one and so on... I don’t play much with PHP so I’m a little lost.
I’ve tried to do with switch
also but I could not.
<?php
#checagem da existencia do arquivo em varias pastas diferentes
$imagem = foto.jpg;
$filename = "img/$imagem";
$filename_dois = "img-2/$imagem";
$filename_tres = "img-3/$imagem";
$filename_quatro = "img-4/$imagem";
$filename_cinco = "img-5/$imagem";
if (file_exists($filename)) {echo "<a href='img/$imagem' rel='shadowbox[cart]'> <img src='timthumb.php?src=img/$imagem_da_certidao&h=150&w=200' /> </a>";} else
{(file_exists($filename_dois)) {echo "<a href='img-2/$imagem' rel='shadowbox[cart]'> <img src='timthumb.php?src=img-2/$imagem&h=150&w=200' /> </a>";}}
else
{(file_exists($filename_tres)) {echo "<a href='img-3/$imagem' rel='shadowbox[cart]'> <img src='timthumb.php?src=img-3/$imagem&h=150&w=200' /> </a>";}}
else
{(file_exists($filename_quatro)) {echo "<a href='img-4/$imagem' rel='shadowbox[cart]'> <img src='timthumb.php?src=img-4/$imagem&h=150&w=200' /> </a>";}}
else
{(file_exists($filename_cinco)) {echo "<a href='img-5/$imagem' rel='shadowbox[cart]'> <img src='timthumb.php?src=img-5/$imagem&h=150&w=200' /> </a>";}}
?>
More than a year later, the code has been very useful. So much so that I adopted this scheme for another adaptation to the front end that I did. The problem is that there is the same file in the declared folders, how to make it stop going through the folders after finding the file declared in
$imagem
? Currently I put thedo
involving all the function you gave me. Thank you.– TTGuy