473,322 Members | 1,501 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,322 software developers and data experts.

Upload File Type Problem

I developed a simple tool to allow users to upload .GIF image files.

It works great on my dev box and $_FILES['file']['type'] returns
"image/gif", but on the prod site it returns "application/octet-stream".

Any suggestions would be greatly appreciated.
Jul 17 '05 #1
8 2231
Xenophobe wrote:
I developed a simple tool to allow users to upload .GIF image files.

It works great on my dev box and $_FILES['file']['type'] returns
"image/gif", but on the prod site it returns "application/octet-stream".


It looks as though your browser was unable to determine the Content-
Type, so it correctly fell back to application/octet-stream. How
would you like to deal with that?

Beware that browsers are not obliged to provide Content-Type
information; nor are they required to provide the original filename
in any form, so you cannot rely on checking the extension, if
present, either.

--
Jock
Jul 17 '05 #2
Yup. It's better use getimagesize() to check the actual image time.

Uzytkownik "John Dunlop" <jo*********@johndunlop.info> napisal w wiadomosci
news:MP************************@News.Individual.NE T...
Xenophobe wrote:
I developed a simple tool to allow users to upload .GIF image files.

It works great on my dev box and $_FILES['file']['type'] returns
"image/gif", but on the prod site it returns "application/octet-stream".


It looks as though your browser was unable to determine the Content-
Type, so it correctly fell back to application/octet-stream. How
would you like to deal with that?

Beware that browsers are not obliged to provide Content-Type
information; nor are they required to provide the original filename
in any form, so you cannot rely on checking the extension, if
present, either.

--
Jock

Jul 17 '05 #3
Hey Jock,

I've look at several alternate ways to determine the file type. I'm somewhat
limited because the web hosting service is running 4.2.3 and most of the
easier ways require 4.3.

I think getimagesize is probably my best option.

Security isn't a huge issue because the admin pages are in a
password-protected directory and will only be used by the client's trusted
staff.

Thanks.

"John Dunlop" <jo*********@johndunlop.info> wrote in message
news:MP************************@News.Individual.NE T...
Xenophobe wrote:
I developed a simple tool to allow users to upload .GIF image files.

It works great on my dev box and $_FILES['file']['type'] returns
"image/gif", but on the prod site it returns "application/octet-stream".


It looks as though your browser was unable to determine the Content-
Type, so it correctly fell back to application/octet-stream. How
would you like to deal with that?

Beware that browsers are not obliged to provide Content-Type
information; nor are they required to provide the original filename
in any form, so you cannot rely on checking the extension, if
present, either.

--
Jock

Jul 17 '05 #4
Is it possible to determine the file type using getimagesize() without
saving the file to disk first? I didn't see anything on php.net, but thought
it didn't hurt to ask.

"Chung Leong" <ch***********@hotmail.com> wrote in message
news:CM********************@comcast.com...
Yup. It's better use getimagesize() to check the actual image time.

Uzytkownik "John Dunlop" <jo*********@johndunlop.info> napisal w wiadomosci news:MP************************@News.Individual.NE T...
Xenophobe wrote:
I developed a simple tool to allow users to upload .GIF image files.

It works great on my dev box and $_FILES['file']['type'] returns
"image/gif", but on the prod site it returns
"application/octet-stream".
It looks as though your browser was unable to determine the Content-
Type, so it correctly fell back to application/octet-stream. How
would you like to deal with that?

Beware that browsers are not obliged to provide Content-Type
information; nor are they required to provide the original filename
in any form, so you cannot rely on checking the extension, if
present, either.

--
Jock


Jul 17 '05 #5
Xenophobe wrote upsidedown:
"Chung Leong" <ch***********@hotmail.com> wrote in message
news:CM********************@comcast.com...
Uzytkownik "John Dunlop" <jo*********@johndunlop.info> napisal w
wiadomosci news:MP************************@News.Individual.NE T...
It looks as though your browser was unable to determine the Content-
Type, so it correctly fell back to application/octet-stream. How
would you like to deal with that?
Yup. It's better use getimagesize() to check the actual image time.


Yes! I'd forgotten about that. Thanks.
Is it possible to determine the file type using getimagesize() without
saving the file to disk first?


Yes, getimagesize has URL support. See

http://www.php.net/manual/en/function.getimagesize.php

It's not possible to determine the image type when it's on the user's
system though.

--
Jock
Jul 17 '05 #6
Xenophobe wrote:
> I developed a simple tool to allow users to upload .GIF image files.
>
> It works great on my dev box and $_FILES['file']['type'] returns
> "image/gif", but on the prod site it returns "application/octet-stream".
It looks as though your browser was unable to determine the Content-
Type, so it correctly fell back to application/octet-stream. How
would you like to deal with that?

Beware that browsers are not obliged to provide Content-Type
information; nor are they required to provide the original filename
in any form, so you cannot rely on checking the extension, if
present, either.


Is it possible to determine the file type using getimagesize() without
saving the file to disk first? I didn't see anything on php.net, but thought
it didn't hurt to ask.


You can use getimagesize on the file while it's still in the tmp directory,
before you move it to a permanent location. You can't use it while it's still
on the user's system.

getimagesize($_FILES['filename']['tmp_name']);

Regards,
Shawn

--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #7
You can't access client side file info w/o using ActiveX and an applet.

I've actually used a nifty third party applet, JUpload. It was development
for use with ASP, but works great with PHP as well.

Anyway, thanks for the info re: getimagesize(). I will implement this right
away.

"John Dunlop" <jo*********@johndunlop.info> wrote in message
news:MP************************@News.Individual.NE T...
Xenophobe wrote upsidedown:
"Chung Leong" <ch***********@hotmail.com> wrote in message
news:CM********************@comcast.com...
Uzytkownik "John Dunlop" <jo*********@johndunlop.info> napisal w
wiadomosci news:MP************************@News.Individual.NE T...

> It looks as though your browser was unable to determine the Content-
> Type, so it correctly fell back to application/octet-stream. How
> would you like to deal with that?

Yup. It's better use getimagesize() to check the actual image time.


Yes! I'd forgotten about that. Thanks.
Is it possible to determine the file type using getimagesize() without
saving the file to disk first?


Yes, getimagesize has URL support. See

http://www.php.net/manual/en/function.getimagesize.php

It's not possible to determine the image type when it's on the user's
system though.

--
Jock

Jul 17 '05 #8
Thanks for the syntax.

"Shawn Wilson" <sh***@glassgiant.com> wrote in message
news:40***************@glassgiant.com...
Xenophobe wrote:
> > I developed a simple tool to allow users to upload .GIF image files. > >
> > It works great on my dev box and $_FILES['file']['type'] returns
> > "image/gif", but on the prod site it returns "application/octet-stream".
>
> It looks as though your browser was unable to determine the Content-
> Type, so it correctly fell back to application/octet-stream. How
> would you like to deal with that?
>
> Beware that browsers are not obliged to provide Content-Type
> information; nor are they required to provide the original filename
> in any form, so you cannot rely on checking the extension, if
> present, either.


Is it possible to determine the file type using getimagesize() without
saving the file to disk first? I didn't see anything on php.net, but thought it didn't hurt to ask.


You can use getimagesize on the file while it's still in the tmp

directory, before you move it to a permanent location. You can't use it while it's still on the user's system.

getimagesize($_FILES['filename']['tmp_name']);

Regards,
Shawn

--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com

Jul 17 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: lawrence | last post by:
I've been using the following function (yes, it is inelegant, what can I say, I wrote it a long time ago) to upload images. Haven't had a problem with it for at least a year, and I don't recall...
1
by: Muttly | last post by:
Hey all. I'm trying to upload multiple files. I'm using the chm file from php.net to help me figure it out. I also checked online and say theres a problem with the file. Anyway My html looks like...
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...
4
by: Matt Jensen | last post by:
Howdy I've got a rather strange issue occuring. I used forms based .NET authentication, although I'm also setting some session variables when people login. However, I've found when people use...
1
by: DavidA | last post by:
I have a very simple form and perl script that is to upload a jpg file. I am not familiar with the perl language but copied the code from a text book. It works fine with all browsers except IE....
7
by: pbd22 | last post by:
hi. i am having probs understanding how to grab a file being uploaded from a remote client. i am using hidden input fields for upload such as: <input id="my_file_element" type="file"...
6
by: =?ISO-8859-1?Q?J=F8rn?= Dahl-Stamnes | last post by:
I have a strange problem when uploading a PDF document to a web-server. When I try this to a web-server running Apache 2 on a FC 4, it fails. Firefox says that the document contain no data. If I...
2
by: Event Horizon | last post by:
Hi, I'm trying to add an simple upload applet to shopping cart script. My new applet form sends all needed post fields ( quantity, product, etc... ) but the "file" post field is hardcoded in...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
1
by: chennaibala | last post by:
can any one send me mutiple image upload program and save the file name with extension in mysql table.we must cheak uploaded file type like bmp or any image file while uploading. i develop...
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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)...
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.