Optional download button

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
subrataa
Forum Newbie
Posts: 4
Joined: Sat Jan 28, 2012 6:20 am

Optional download button

Post by subrataa »

Hi..
Any one please tell me what is the method going on after this link : (download button) http://www.cell93.com/angels/wallpapers/
Please help me out...
Here is a php file in server named “download.php” , I tried using too many php code to active download like this but each of every time, I failed.
Please help me to figure out this code..
Or please refer me with another code by which I can create this type of optional download button using php.
Looking forward to hear from you soon..
Thanks,
Subrata Samanta
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Optional download button

Post by Celauran »

It's just a regular form submit button. The target page determines which file was requested and sends the appropriate headers as response, namely Content-disposition.
subrataa
Forum Newbie
Posts: 4
Joined: Sat Jan 28, 2012 6:20 am

Re: Optional download button

Post by subrataa »

Can you please help me with code.
Please!
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Optional download button

Post by Celauran »

What have you got so far? Where are you running into trouble?
subrataa
Forum Newbie
Posts: 4
Joined: Sat Jan 28, 2012 6:20 am

Re: Optional download button

Post by subrataa »

actually i'm not a php developer.. i like php.. want to learn more & more..
but there is a quick requirement of this code.. for that i beg to plz help me with this code.
My e-mail address : subratasamantahere@gmail.com
please reply me..
subrataa
Forum Newbie
Posts: 4
Joined: Sat Jan 28, 2012 6:20 am

Re: Optional download button

Post by subrataa »

I got a php code from internet that is:

Code: Select all


<?php

// place this code inside a php file and call it f.e. "download.php"
$path = $_SERVER['DOCUMENT_ROOT']."/path2file/"; // change the path to fit your websites document structure
$fullPath = $path.$_GET['download_file'];

if ($fd = fopen ($fullPath, "r")) {
    $fsize = filesize($fullPath);
    $path_parts = pathinfo($fullPath);
    $ext = strtolower($path_parts["extension"]);
    switch ($ext) {
        case "pdf":
        header("Content-type: application/pdf"); // add here more headers for diff. extensions
        header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachment' to force a download
        break;
        default;
        header("Content-type: application/octet-stream");
        header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
    }
    header("Content-length: $fsize");
    header("Cache-control: private"); //use this to open files directly
    while(!feof($fd)) {
        $buffer = fread($fd, 2048);
        echo $buffer;
    }
}
fclose ($fd);
exit;
// example: place this kind of link into the document where the file download is offered:
// <a href="download.php?download_file=some_file.pdf">Download here</a>
?>
but i don't know how to edit it..
Please help me,
I sent a link where i want to test it : http://www.pixyedges.com/subrata/
you can find all the images & folder structure here
please help me out..
Post Reply