468,268 Members | 1,764 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,268 developers. It's quick & easy.

Image MIME/file type

Hi All,

Is there a way to get PHP to change the mime type for a file sent to a
browser.

I need my website viewers to be able to click a link to directly download
and save an image, rather than the browser displaying it.

Is there some other way to make this happen?

Thanks

David
Nov 7 '06 #1
4 7245
Vertuas:
Is there a way to get PHP to change the mime type for a file sent to a
browser.
header('Content-Type: example/*')
I need my website viewers to be able to click a link to directly download
and save an image, rather than the browser displaying it.
Why?
Is there some other way to make this happen?
Look up Content-Disposition, but don't hold your breath.

--
Jock

Nov 7 '06 #2
Hi John

The images are purchased by the user, having them go through an instructions
page for there browser telling them to right click and save as an all that
i't would be nicer if they could click a download link, give it a name and
job done.

Trouble is linking to the image results in the browser displaying the image,
rather than downloading it.

Thanks for the reply.

David

"John Dunlop" <us*********@john.dunlop.namewrote in message
news:11**********************@h54g2000cwb.googlegr oups.com...
Vertuas:
>Is there a way to get PHP to change the mime type for a file sent to a
browser.

header('Content-Type: example/*')
>I need my website viewers to be able to click a link to directly download
and save an image, rather than the browser displaying it.

Why?
>Is there some other way to make this happen?

Look up Content-Disposition, but don't hold your breath.

--
Jock

Nov 7 '06 #3
In article <u%*******************@newsfe6-gui.ntli.net>, Vertuas says...
Hi All,

Is there a way to get PHP to change the mime type for a file sent to a
browser.

I need my website viewers to be able to click a link to directly download
and save an image, rather than the browser displaying it.

Is there some other way to make this happen?
You need to send content-type and content-disposition headers, example:

header('Content-type: image/png');
header('Content-disposition: attachment; filename="'$filename'"');
--
PleegWat
Remove caps to reply
Nov 7 '06 #4
Thanks again guys

I found this code on php website

$f = fopen("file.txt", "rb");
$content_len = (int) filesize($f, "file.txt");
$content_file = fread($f, $content_len);
fclose($f);

$output_file = 'MXimage.jpg';

@ob_end_clean();
@ini_set('zlib.output_compression', 'Off');
header('Pragma: public');

header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1
header('Cache-Control: pre-check=0, post-check=0, max-age=0'); // HTTP/1.1
header('Content-Transfer-Encoding: none');
header('Content-Type: application/octetstream; name="' . $output_file .
'"'); //This should work for IE & Opera
header('Content-Type: application/octet-stream; name="' . $output_file .
'"'); //This should work for the rest
header('Content-Disposition: inline; filename="' . $output_file . '"');
header("Content-length: $content_len");

echo $content_file;
exit()

the filename MXimage.jpg is my own test image file.

when i point IE at it, i get a message about a 3 byte HTML file. Why does
that image file not come through? It seams that the script doesn't even pass
the image data on.

is this something to do with the way PHP handeles the headers. Its running
on a Linux host.

Thanks again

"Vertuas" <ve*****@hotmail.comwrote in message
news:u%*******************@newsfe6-gui.ntli.net...
Hi All,

Is there a way to get PHP to change the mime type for a file sent to a
browser.

I need my website viewers to be able to click a link to directly download
and save an image, rather than the browser displaying it.

Is there some other way to make this happen?

Thanks

David

Nov 7 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Michael J. Astrauskas | last post: by
3 posts views Thread by dave | last post: by
reply views Thread by doffer | last post: by
2 posts views Thread by Adam Teale | last post: by
7 posts views Thread by xx75vulcan | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.