koo_04 Posted February 8, 2011 Share Posted February 8, 2011 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>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/227091-download-file-from-a-glob-list/ Share on other sites More sharing options...
lastkarrde Posted February 8, 2011 Share Posted February 8, 2011 Well, using glob and basename you can work out the full path of the file. Append/alter that pathname so it is a valid URL. Then just download the file with cURL or file_get_contents. Quote Link to comment https://forums.phpfreaks.com/topic/227091-download-file-from-a-glob-list/#findComment-1171549 Share on other sites More sharing options...
koo_04 Posted February 10, 2011 Author Share Posted February 10, 2011 Sounds good to me. Should I be doing like this? foreach($files as $file){ echo '<p><a href="'file_get_contents(.basename($file).'">'.basename($file).'</a></p>'; }; I keep getting a broken server from it though. Quote Link to comment https://forums.phpfreaks.com/topic/227091-download-file-from-a-glob-list/#findComment-1172190 Share on other sites More sharing options...
koo_04 Posted February 10, 2011 Author Share Posted February 10, 2011 EDIT: I have tired this and got a really crazy page... I will keep put up a screen shot. foreach($files as $file){ echo '<p><a href="'.file_get_contents($file).'">'.basename($file).'</a></p>'; }; Quote Link to comment https://forums.phpfreaks.com/topic/227091-download-file-from-a-glob-list/#findComment-1172192 Share on other sites More sharing options...
salathe Posted February 10, 2011 Share Posted February 10, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/227091-download-file-from-a-glob-list/#findComment-1172212 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.