Skip to main content
Inspiring
February 14, 2008
Question

forced downloaded images corrupted

  • February 14, 2008
  • 2 replies
  • 717 views
hi:

i have this script (found in this forum) i've used to force pdf files
downloading w/o problems

now i want to use it for images (jpg), so i changed

$ctype="application/pdf";

to

$ctype="image/jpg";

the images d/l but when i try to open them i receive error messages:

Preview: Couldn't open the file. It may be corrupt or a file format that
Preview doen't recognize

Photoshop: The file can't be opened because the segment marker is too
short (probably the file is incompleted)

any ideas?

tia,

jdoe

> <?php
> $filenum = $_GET['file'];
>
> switch($filenum) {
> case '0': $filename="media/...."; break;
> case '1': $filename="media/...."; break;
> }
>
> // required for IE, otherwise Content-disposition is ignored
> if(ini_get('zlib.output_compression'))
> ini_set('zlib.output_compression', 'Off');
>
> // addition by Jorg Weske
> $file_extension = strtolower(substr(strrchr($filename,"."),1));
>
> $ctype="application/pdf";
> header("Pragma: public"); // required
> header("Expires: 0");
> header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
> header("Cache-Control: private",false); // required for certain browsers
> header("Content-Type: $ctype");
> // change, added quotes to allow spaces in filenames, by Rajkumar Singh
> header( "Content-Description: File Transfer");
> header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" );
> header("Content-Transfer-Encoding: binary");
> header("Content-Length: ".filesize($filename));
> readfile("$filename");
> exit();
> ?>
This topic has been closed for replies.

2 replies

Inspiring
February 17, 2008
David Powers wrote:
> John Doe wrote:
>> $ctype="image/jpg";
>
> The correct MIME type is image/jpeg. Internet Explorer, however, uses
> image/pjpeg.
>

thanks, it's working fine now, even in IE 6/7
Inspiring
February 14, 2008
John Doe wrote:
> $ctype="image/jpg";

The correct MIME type is image/jpeg. Internet Explorer, however, uses
image/pjpeg.

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/