Listing Folder Files with PHP

1

Hello, I did this program that lists the photos in my directory, but I just wanted to click on the photo list to see the photo on screen with php.

 <?php

 $path = "C:\FOTOS COOPERADOS 2013";
   $diretorio = dir($path);

    echo "Lista de Arquivos do diretório '<strong>".$path."</strong>':<br />";    
   while($arquivo = $diretorio -> read()){
      echo "<a href='".$path.$arquivo."'>".$arquivo."</a><br />";
   }
   $diretorio -> close();
?>

    
asked by anonymous 31.08.2016 / 14:07

2 answers

-1

On select you can put everything in array or search the values in the database if you have, I put an example with array :

<?php

$perspectiva = array();

$perspectiva[1] = "Financeiro";
$perspectiva[2] = "Comercial";
$perspectiva[3] = "Administrativo";
$perspectiva[4] = "Cooperados";
$perspectiva[5] = "Aprendizagem";
$perspectiva[6] = "Rede";
$perspectiva[7] = "Assistencia Hospitalar";
$perspectiva[8] = "Comunicaçao e Marketing";

?>

<?php if( is_array($perspectiva) and count($perspectiva) > 0 ){ ?> 
    <select name="perspectiva">
        <?php foreach( $perspectiva as $key => $value ){ ?>

            <option value="<?php echo $key; ?>"><?php echo $value; ?></option>

        <?php } ?>
    </select> 
<?php } ?>


<?php

// Exemplo de como recuperar o valor
$o_que_quero_mostrar = 6; // Rede   

echo $perspectiva[$o_que_quero_mostrar];

?>
    
01.09.2016 / 22:17
0

Use normal bar instead of backslash in $path , in addition, add a bar at the end.

What's like this:

$path = "C:\FOTOS COOPERADOS 2013";

It should look like this:

$path = "C:/FOTOS COOPERADOS 2013/";

Next, add the prefix file:/// because it is a local file.

What's like this:

echo "<a href='".$path.$arquivo."'>".$arquivo."</a><br />";

It should look like this:

echo "<a href='file:///".$path.$arquivo."'>".$arquivo."</a><br />";

See the complete code:

<?php

    $path = "C:/FOTOS COOPERADOS 2013/";
    $diretorio = dir($path);
    echo "Lista de Arquivos do diretório '<strong>".$path."</strong>':<br />";    
    while($arquivo = $diretorio -> read()){
       echo "<a href='file:///".$path.$arquivo."'>".$arquivo."</a><br />";
    }
    $diretorio -> close();

Clicking the link should open a URL similar to:

file:///C:/FOTOS%20COOPERADOS%202013/seu_arquivo.jpg
    
31.08.2016 / 14:29