marthy Posted September 16, 2015 Share Posted September 16, 2015 i wanna know if it is possible to add a download button to this script: http://dumptext.com/sR6ZRBFO it is set up so it finds all files i my directory and displays them but i want a way to download the files i click i must admid i dont know much about this coding lanuage and found this file on the web together with a set of files i need to make it beatifull and such any help is apreciated Quote Link to comment https://forums.phpfreaks.com/topic/298190-download-button-to-script/ Share on other sites More sharing options...
QuickOldCar Posted September 16, 2015 Share Posted September 16, 2015 (edited) To make it easy can do a form with action leading to the file or as href and set the download attribute <form method="get" action="<?php echo $file;?>"> <button type="submit">Download</button> </form> or <a href="<?php echo $file;?>" download="<?php echo $file;?>">Download</a> Edited September 16, 2015 by QuickOldCar Quote Link to comment https://forums.phpfreaks.com/topic/298190-download-button-to-script/#findComment-1520955 Share on other sites More sharing options...
marthy Posted September 16, 2015 Author Share Posted September 16, 2015 To make it easy can do a form with action leading to the file or as href and set the download attribute <form method="get" action="<?php echo $file;?>"> <button type="submit">Download</button> </form> or <a href="<?php echo $file;?>" download="<?php echo $file;?>">Download</a> ok sorry about the on and off going best answer first. where do i apply this ? Quote Link to comment https://forums.phpfreaks.com/topic/298190-download-button-to-script/#findComment-1520956 Share on other sites More sharing options...
QuickOldCar Posted September 16, 2015 Share Posted September 16, 2015 I was being lazy and not want to go scour your code and figure out what you want to link to. The place where you say want a download button is where. <a href="<?php echo $file;?>" download="<?php echo $file;?>">Download</a> $file being that files variable, use w/e variable you use in your script. Quote Link to comment https://forums.phpfreaks.com/topic/298190-download-button-to-script/#findComment-1520959 Share on other sites More sharing options...
marthy Posted September 16, 2015 Author Share Posted September 16, 2015 I was being lazy and not want to go scour your code and figure out what you want to link to. The place where you say want a download button is where. <a href="<?php echo $file;?>" download="<?php echo $file;?>">Download</a> $file being that files variable, use w/e variable you use in your script. can is use it in this part ? <table class="sortable"> <thead> <tr> <th>Filename</th> <th>Type</th> <th>Size</th> <th>Date Modified</th> <th><a href="<?php echo $file;?>" download="<?php echo $file;?>">Download</a></th> </tr> </thead> <tbody> like this ? Quote Link to comment https://forums.phpfreaks.com/topic/298190-download-button-to-script/#findComment-1520960 Share on other sites More sharing options...
marthy Posted September 16, 2015 Author Share Posted September 16, 2015 I was being lazy and not want to go scour your code and figure out what you want to link to. The place where you say want a download button is where. <a href="<?php echo $file;?>" download="<?php echo $file;?>">Download</a> $file being that files variable, use w/e variable you use in your script. can it maybe be here ? i am such a loser in this sorry echo(" <tr class='$class'> <td><a href='./$namehref'$favicon class='name'>$name</a></td> <td><a href='./$namehref'>$extn</a></td> <td sorttable_customkey='$sizekey'><a href='./$namehref'>$size</a></td> <td sorttable_customkey='$timekey'><a href='./$namehref'>$modtime</a></td> </tr>"); Quote Link to comment https://forums.phpfreaks.com/topic/298190-download-button-to-script/#findComment-1520961 Share on other sites More sharing options...
Solution QuickOldCar Posted September 16, 2015 Solution Share Posted September 16, 2015 It's ok if new to this, is just this script not the best. Using glob() much better. Horrible the way doing if/else directories and files, not defining the directory location for each file. if(is_file("./".$namehref)){ $download = "download='./$namehref' target='_blank'"; }else{ $download = ''; } // Output echo (" <tr class='$class'> <td><a href='./$namehref' $download>$namehref</a></td> <td>$extn</td> <td sorttable_customkey='$sizekey'>$size</td> <td sorttable_customkey='$timekey'>$modtime</td> </tr>"); Quote Link to comment https://forums.phpfreaks.com/topic/298190-download-button-to-script/#findComment-1520964 Share on other sites More sharing options...
marthy Posted September 16, 2015 Author Share Posted September 16, 2015 It's ok if new to this, is just this script not the best. Using glob() much better. Horrible the way doing if/else directories and files, not defining the directory location for each file. if(is_file("./".$namehref)){ $download = "download='./$namehref' target='_blank'"; }else{ $download = ''; } // Output echo (" <tr class='$class'> <td><a href='./$namehref' $download>$namehref</a></td> <td>$extn</td> <td sorttable_customkey='$sizekey'>$size</td> <td sorttable_customkey='$timekey'>$modtime</td> </tr>"); thank you for your help it worked like a charm Quote Link to comment https://forums.phpfreaks.com/topic/298190-download-button-to-script/#findComment-1520968 Share on other sites More sharing options...
QuickOldCar Posted September 16, 2015 Share Posted September 16, 2015 If I find my recursive directories and files script using glob will post it here. Could take a long time to find it. Quote Link to comment https://forums.phpfreaks.com/topic/298190-download-button-to-script/#findComment-1520969 Share on other sites More sharing options...
Barand Posted September 16, 2015 Share Posted September 16, 2015 (edited) Here's a basic recursive glob() script $dir = 'c:/inetpub/wwwroot/'; // set start directory dirList($dir); // call the recursive function function dirList($dir, $level=0) { $files = glob($dir.'/*'); foreach ($files as $f) { if (is_dir($f)) continue; echo str_repeat('|---- ', $level) . basename($f) . '<br>'; } $files = glob($dir.'/*', GLOB_ONLYDIR); foreach ($files as $f) { if (is_dir($f)) { echo str_repeat('|---- ', $level) . "<strong>$f</strong><br>"; dirList($f, $level+1); } } } Edited September 16, 2015 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/298190-download-button-to-script/#findComment-1520975 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.