0

In my web site, i would like to allow visitors to download pictures. I displaye the picture in the following way

<a href="" ><img  src = "picture" .../> </A>

When the visitor clik on the link, how to begin the downloading of the picture ??

The second question, if i have many links, how can i zip pictures in a single directory and allow the downloding of the the zip?

hakre
  • 193,403
  • 52
  • 435
  • 836
Mamadou
  • 2,177
  • 5
  • 31
  • 43

3 Answers3

1

Here's the PHP to download a file.

<?php
$rootPath = "files/";

$filename = "output.txt";
$orig_filename = $_POST[ 'filename' ];

$filename = $rootPath . $filename;
$filesize = filesize( $filename );

if ( $fd = fopen( $filename, "r" ))
{
    header( "Content-type: application/octet-stream" );
    header( "Content-Disposition: filename=\"$orig_filename\"" );
    header( "Content-length: $filesize " );
    header( "Cache-control: private" );

    while( !feof( $fd ))
    {
        $buffer = fread( $fd, 1024 );
        echo $buffer;
    }

    fclose( $fd );
}

exit;

?>
ethrbunny
  • 10,379
  • 9
  • 69
  • 131
0
<a href="/path/to/image" download="ImageName" title="ImageName">
    <img src="/path/to/image" alt="ImageName">
</a>

This only works on modern browsers though....