0

I'm trying to list files in a folder. I have done this before, so I am not sure why I am having a problem now.

I have a PDF files I am trying to display to my web page. The directory structure looks like this:

folder1/folder2/displayFiles.php
folder1/folder2/files.pdf

displayFiles.php is the process file where I am using the code below.

I am trying to display the file called files.pdf onto the page, which is in the same directory as the process file.

Here is my code so far:

 <?php
   $dir = "folder1/folder2/"; 
   // $dir = "/";  <-- I also tried this
   $ffs = scandir($dir);

   foreach($ffs as $ff)
   {
     if($ff != '.' && $ff != '..')
     {
       $filesize = filesize($dir . '/' . $ff);  
       echo "<ul><li><a download href='$dir/$ff'>$ff</a></li></ul>";
     }
   }
 ?>

I know it's a simple fix. I just cannot find the code to fix it.

2
  • 1
    Change the dir to point to the folder correctly $dir = "."; Commented Oct 17, 2016 at 14:40
  • @RiggsFolly - This is exactly what I needed to fix this. I knew it was a simple fix. If you create an answer below, I will accept it. Thank you. Commented Oct 17, 2016 at 14:42

2 Answers 2

1

Your $dir is pointing at a non-existent folder

Change the dir to point to the folder correctly $dir = ".";.

Sign up to request clarification or add additional context in comments.

Comments

1

Just use glob

http://php.net/manual/de/function.glob.php

$pdfs = glob("*.pdf"); // if needed loop through your directorys and glob files
print_r($pdfs);

Just an example. You should be able to use it with some edits.

1 Comment

thank you, sir. I was able to use the method @RiggsFolly suggested above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.