Jump to content

Recommended Posts

Hopefully someone can help me with some coding issues that Im having

 

 

Back Story

I have a website that has hundreds of thousands of PDFS that are listed and linked on a web server 

The layout on the server is /PDFS/1-4/file.pdf etc etc

and on the site its listed <a href="/PDF/1-4/1 ACADEMIC SQ.pdf" target="_blank">1 ACADEMIC SQ</a><br>

 

Ive been manually changing the file names in the link when a new file is added to the server.

 

I want to automate the proccess where when a file is added to the "PDF/1-4/" folder  itll update the webpage 1-4.html etc with the new links and sorted alphabetically 

 

Im VERY new to PHP and so far the only thing that I have is but its not working 

<?php 
$dirname = '/var/www/download_folder';
$webdirname = '/download_folder';

$dir = opendir($dirname); 
$file_list = ''; 

while(($file = readdir($dir)) != false) { 
if(($file != '.') && ($file != '..')) { 
$file_list .= "<a href=\"$webdirname/$file\">$file</a><br/>"; 
} 
} 

closedir($dir); 
?> 

<p> 
<?=$file_list?> 
</p>

Any guidance would be greatly appreciated 

You said you want to update some static HTML file, but “your” code (which I assume you have copied and pasted from somewhere) has nothing to do with that at all. It generates a list of files dynamically. So what is it?

 

A dynamic list is definitely the better approach. However, it makes no sense to print the entire directory content. If you want a simple directory listing, use your webserver. Apache, nginx etc. all have this feature. If you want a more intelligent approach (pagination, meta data, previews, ...), I recommend you store references to your files in a database where you can manage them properly. PHP usually comes with MySQL, so all you have to do is learn a few SQL basics – which you'll need anyway, sooner or later.

Edited by Jacques1

On the simple directory listing:

 

Make sure you don't have an index.php or .html or .anything in the PDF directory or any of its subdirectories. Now go to /PDF in your browser. What happens? If you get a 403 Forbidden page then that can be fixed, but there's a good chance you'll get a listing of all the files and directories in there. And with no* work on your part.

 

* Your experience may vary.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.