Jump to content

download button to script


Go to solution Solved by QuickOldCar,

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/298190-download-button-to-script/
Share on other sites

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 by QuickOldCar

 

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 ?

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.

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 ?

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>");

    

  • Solution

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>");

 

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 :happy-04:

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