Hi guys,

I have on my server some images. I want people to be able to select the images they want to download through a form then hit download. Then the regular download prompt appears.

Can anyone help me this or show me where to begin looking to achieve something like this?

Thanks

Recommended Answers

All 8 Replies

you need an image gallery script like this one LINK

You can download a copy from ( Click here )

Hi ApocDen,

Thanks for your reply. I have already made my own gallery and what not. But what I want is to have the user tick a checkbox under each image and then hit download to download each image.

The only bit im having trouble with is how to make to images actually download with the regular prompt rather than right click and save as..

oh thats easy you need to force download using readfile().

try this script

<?php
$file = 'Denis.png';

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
}
?>

Its easy if you use a premade gallery script, you dont have to use the script as your script, but it may provide insight to methods to accomplish what you intend <a href='download.php?img=thisimage.jpg'><img src='thisimagethumb.jpg' /></a> download.php

<?php if(!$img) return false;
header("Content-disposition: attachment; filename=$img");
header('Content-type: image/jpeg;');
readfile("$img");
?>

Pisspoor code, but it may provide a starting point

Does this work on external servers? I'm making an app for bebo and using their API all i get is the URL's of the images. Can I use the URL provided in this method?

Does this work on external servers? I'm making an app for bebo and using their API all i get is the URL's of the images. Can I use the URL provided in this method?

It would have been nice, intelligent, logical, to include this nugget, gem, of information in the initial post

http://developer.bebo.com/downloads/example-libs-php.php at http://developer.bebo.com/ $bebo->photos_get(); is the part of the API you're interested in,
most file servers are configured to block external access, BUT bebo apps like facebook apps run on the bebo server so should work

Hi AlmostBob,

"It would have been nice, intelligent, logical, to include this nugget, gem, of information in the initial post" - a bit of a harsh statement. Thanks for the help but any chance we can keep the insults to my intelligence out of this?

As I said above I have everything I need bar being able to download the images. I am already using

$bebo->photos_get();

to get the direct url to the images. What I want to do is to force a download of these files.

I have been thinking about it the last while and I'm thinking the best thing for me to do would probably rather than do a force download of the images(because you would only be able to do it one image at a time) would be to copy the images to my server, zip them, download to the users computer and then unset the images from my server.

Any one have any better theories?


I would have included that if it were relevant but all that function does is return information about the image such as it's url. I'm already using this.

So I already have the URL's of the images

Yes: for remote file you may use $image = file_get_contents($fileurl);
in place of readfile();
If this fails in your server you may use curl like this

<?php
    $file = $url of the image file;
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    $data = $imageurl;
    $ch = curl_init($data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,2);
    $image = curl_exec($ch); 
    exit;
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.