Jump to content

Download file from a Glob list


koo_04

Recommended Posts

I would like to go from a glob list, which is working great, to a download link kinda thing. So, The glob list is shown and each file has a link. The problem is that the download folder for PHP is apparently NOT within my website, but in another portion of the server. Also that when I modify the code to work within the website, it doesnt work. Probably because of the glob array. Anyone have an idea on how to fix this?

 

Code:

<?php
$dir = "/downloads/";
$files = glob($dir."*.zip", GLOB_NOSORT);
// echo'<select name="Files">';
foreach($files as $file){
// echo'<option value="'.$file.'">'.basename($file).'</option>';
echo '<p><a href="/downloads/'.basename($file).'">'.basename($file).'</a></p>';
};
// echo'</select>';
?>

Link to comment
https://forums.phpfreaks.com/topic/227091-download-file-from-a-glob-list/
Share on other sites

The only thing that you likely need to change from the code in the first post are the two occurrences of /downloads/.  Unless of course your files live in /downloads/*.zip (an absolute path from the root of your server, not the web root, not relative to the the PHP script!) and in /path/to/web/root/downloads/*.zip.

 

So, the first /downloads/ should be the path to the files on the server filesystem either absolute (E.g. /home/myserver/downloads/) or relative to the script (E.g. ./downloads/). Then the second /downloads/ should be the web path of the files (which might be /downloads/).

 

There's absolutely no need for your script to use cURL or file_get_contents() on the files.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.