473,320 Members | 1,957 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 7481
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Phil Powell | last post by:
How do you detect an image MIME type if you know of the image in a directory? For example, I know of: if (is_file("$myImagePath/$myImageName")) { // FIND MIME TYPE BUT HOW I DUNNO } The...
7
by: Michael J. Astrauskas | last post by:
I have a script, which I've called test-loadpic.php and some pages reference it by means of <img src="test-loadpic.php?sourcepic=$picNum"> where $picNum stores a number. This part itself works...
3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
7
by: Dobedani | last post by:
Dear All, I am developing / maintaining a web application which generates GIF images on the fly. When I send the image, I make sure a header is sent first with MIME-type image/gif. My HTML-code...
0
by: doffer | last post by:
I want to make a portfoliosystem where user can register and get their own portfolio... I've started the developer work, but I'm stuck on the image upload part... I'm experiencing some problems...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
14
by: =?Utf-8?B?U2FtdWVs?= | last post by:
Hi, I have a web app that allows others to upload files, and the problem is that if I allow users to upload image files, fake image can be uploaded and cause XSS issues. In the app, I do...
2
by: Adam Teale | last post by:
hey guys Is there a builtin/standard install method in python for retrieving or finding out an image's dimensions? A quick google found me this:...
7
by: xx75vulcan | last post by:
Hi, I've got a PHP Upload Form that works great, unless that is, the image your uploading has been modified through a photo editing software. Example: if I upload the image straight from a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.