Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

forced downloaded images corrupted

LEGEND ,
Feb 13, 2008 Feb 13, 2008
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();
> ?>
TOPICS
Server side applications
720
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 14, 2008 Feb 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/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 17, 2008 Feb 17, 2008
LATEST
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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines