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

Link to comment
Share on other sites

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.