Listing folder files with PHP

Asked

Viewed 3,539 times

1

Hello I made this program that lists the photos of my directory , only I wanted that when clicking on the list of the photo appears 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();
?>

inserir a descrição da imagem aqui

  • already tried so? echo "<a href='". $file." '>". $file." </a><br />";

  • yes give the following error Object not found! The requested URL was not found on this server. The link on the mentioned page seems to be in error or out of date. Please inform the author of this page about the error.

  • Ok, show how the link of an image does not open

2 answers

0

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

What’s the matter with you:

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

should look like this:

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

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

What’s the matter with you:

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

Should stay like this:

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

See the full 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();

When clicking on the link, a URL similar to:

file:///C:/FOTOS%20COOPERADOS%202013/seu_arquivo.jpg
  • It lists , but when you click on the link he listed from the image it does not open anything. How could you be doing to display the listed image from the directory .

  • show how the file address looks when opening nothing, copy and paste to us the browser address.

  • updated the question with the photo

  • would look like this file://C:/PHOTOS%20COOPERADOS%202013/Dr.%20Adilson%20Mota%20-%20Anstesiology%20-%20HMU%201.JPG

  • yes. it lists more when clicking on Lonk to open the photo in the browser does not open

  • happens when you click on the link?

  • Try to let this 20% out of the url like this: preg_replace("20%", " ", $path. $file)

  • @Allanandrade How can I print with php the Financial , because I echo the ['perspective'] she just print the 1 but I want to print the name Finaceiro . How can I do ? <select name="perspective"> <option value="1">Financial</option> </select>

  • @Fabianocacinpinel How can I print with php the Financial , because I echo the ['perspective'] she just print the 1 but I want to print the name Finaceiro . How can I do ? <select name="perspective"> <option value="1">Financial</option> </select>

  • 1

    @allanaraujo did not understand what you meant, I think you wrote your doubt on the wrong topic. What Financial you are talking about?

  • @Fabianocacinpinel what I put in the question .

  • @allanaraujo, you must change the questions only to clarify the object of the same. It should not include things that have nothing to do with the initial question. I ask you again to read the help to understand how the site works. I reversed the question to the original subject.

Show 7 more comments

-1


About the select you can put it all in one array or fetch 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];

?>
  • And to list in place of the array my database as it could be doing ?

  • @allanaraujo You will make a normal query to the database, if I am not mistaken mysql_fetch_array will return this array to you, but I am not sure, try to do if you can not open another topic with your questions.

  • Thanks you helped so much .

Browser other questions tagged

You are not signed in. Login or sign up in order to post.