IanFraz Posted February 1, 2017 Share Posted February 1, 2017 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 Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted February 1, 2017 Share Posted February 1, 2017 (edited) 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 February 1, 2017 by Jacques1 Quote Link to comment Share on other sites More sharing options...
requinix Posted February 1, 2017 Share Posted February 1, 2017 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.