472,973 Members | 2,399 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,973 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 7451
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.