kassprek
kassprek

Reputation: 1007

image button "save as" to save file from external servers php script

I have a pictrures gallery on my server. The pictures are stored on diffrent external servers. On my server are placed the thumbnails only. How I can make a button "save as" in php so that a user can download a big picture file which is from external servers. I need a simple php script which can do download a jpg file cross all browser agents and from diffrent external servers. The button will be implemented inside html code. The button is a regular link formated in css style. So how to do it properly. Thanks.

I would like also that the path of file should be send as a variable parameter to php script somehow.

Upvotes: 0

Views: 3649

Answers (3)

user2254771
user2254771

Reputation: 1

Remove the spaces from your file name:

change: http://backalleypics.com/Pictures/Letter Je~Ju/Jessica Alba/Jessica Alba 230.jpg

to: http://backalleypics.com/Pictures/Letter_Je~Ju/Jessica_Alba/Jessica_Alba_230.jpg

Upvotes: 0

kassprek
kassprek

Reputation: 1007

I found some solution with following php script

<?PHP
 // Define the path to file
 $file = $_GET['file'];
 $name = basename ($file);
 if(!file)
 {
 // File doesn't exist, output error
 die('file not found');
 }
 else
 {
 // Set headers
 header("Cache-Control: public");
 header("Content-Description: File Transfer");
 header("Content-Disposition: attachment; filename=$name");
 header("Content-Type: image/jpg");
 header("Content-Transfer-Encoding: binary");

 // Read the file from disk
 readfile($file);
 }
 ?>

and I can send parameters like url address cross html code

<a href="download.php?file=http://someserver/picture.jpg">download</a>

The only problem is that it is not working with all servers. It's not woriking for exemple with that file

http://backalleypics.com/Pictures/Letter Je~Ju/Jessica Alba/Jessica Alba 230.jpg

I don't know what I need to do?

Upvotes: 0

andrewk
andrewk

Reputation: 3871

I am guessing you are trying to have the pictures be downloaded automatically (you want a dialog box to pop up prompting where to save the file).

There is a great tutorial on this site that uses the php header function to force download

Check it out: http://www.ryboe.com/tutorials/php-headers-force-download

Upvotes: 1

Related Questions