开发者

Allow visitors to dowload files in my site ( php, javascript, html )

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 ?开发者_如何学Python?

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?


Set the apache setting::
http://mark.koli.ch/2009/09/apache-setting-the-content-disposition-header-with-mod-rewrite.html


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;

?>


<a href="/path/to/image" download="ImageName" title="ImageName">
    <img src="/path/to/image" alt="ImageName">
</a>

This only works on modern browsers though....

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜