473,491 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Check the file extension

190 New Member
Hi,

I want to check the extension of uploaded file.

I upload the bmp image using file property. Now i am going to edit the file upload text as bmp file into gif...

example : i upload c:/sample.bmp now i manually edit the file input box as c:/sample.gif and i upload this one.

Now i want to check the orignial file ext.. is there any way in javascript or php.....
Sep 20 '08 #1
10 3816
Atli
5,058 Recognized Expert Expert
Hi.

What do you mean by: "manually edit the file input box"?
What are you doing with the files after you upload them?

You need to explain this a lot better.
Sep 20 '08 #2
pbmods
5,821 Recognized Expert Expert
Heya, maheswaran.

Instead of validating the extension, try validating the mime-type of the file itself. The Fileinfo extension works very well for this (http://php.net/finfo_file).
Sep 20 '08 #3
chelvan
90 New Member
hi

use the following for your if condition

$_FILES["file"]["type"];



regards

chel-1
Sep 22 '08 #4
Atli
5,058 Recognized Expert Expert
hi

use the following for your if condition

$_FILES["file"]["type"];



regards

chel-1
It's not good to rely on that tho. This is supplied by the client, so it can be manipulated.

From the manual:
$_FILES['userfile']['type']
The mime type of the file, if the browser provided this information. An example would be "image/gif". This mime type is however not checked on the PHP side and therefore don't take its value for granted.
Sep 22 '08 #5
maheswaran
190 New Member
Hi Atli,

Manually do means..

First i upload a file...

Now input box have <input type="file" name="uploadto" value="c:/sample.gif">

Then am going to change the value gif as jpg <input type="file" name="uploadto" value="c:/sample.jp..."


After change am going to upload..so am have error... In that case i want to check the file extension or file validation....
Sep 22 '08 #6
chelvan
90 New Member
It's not good to rely on that tho. This is supplied by the client, so it can be manipulated.

From the manual:
hi
thanks for your information.

find out the "/" position then using substr() the user can check the extension. this is the way i thought.

so......... the above is wrong no?


thanks
chel-1
Sep 22 '08 #7
Atli
5,058 Recognized Expert Expert
Hi Atli,

Manually do means..

First i upload a file...

Now input box have <input type="file" name="uploadto" value="c:/sample.gif">

Then am going to change the value gif as jpg <input type="file" name="uploadto" value="c:/sample.jp..."
How do you upload that first file?

Setting the "value" attribute on a <input type="file"> element should have no effect. It will simply be ignored. You will actually have to hit the "browse" button and manually select a file before submitting the form.

After change am going to upload..so am have error... In that case i want to check the file extension or file validation....
What error are you getting?
Can we see the code you are using?

It's very hard to understand the problem without the code, especially with such a limited description of what it is you are doing.
Sep 22 '08 #8
Atli
5,058 Recognized Expert Expert
hi
thanks for your information.

find out the "/" position then using substr() the user can check the extension. this is the way i thought.

so......... the above is wrong no?


thanks
chel-1
The file extension is also a very unreliable way to determine the type of a file.
I could simply add a ".jpeg" extension to any file and your script would accept it as a JPEG image.

Using the method suggested by pbmods is much more reliable. It actually checks the file, not just the file name or the data feed to you by the client.
Sep 22 '08 #9
chelvan
90 New Member
The file extension is also a very unreliable way to determine the type of a file.
I could simply add a ".jpeg" extension to any file and your script would accept it as a JPEG image.

Using the method suggested by pbmods is much more reliable. It actually checks the file, not just the file name or the data feed to you by the client.
hi atli !
thanks for your information
chel-1
Sep 22 '08 #10
maheswaran
190 New Member
yes pbmods code is seems to be fine.Thanks
Sep 22 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

5
8360
by: bart plessers | last post by:
Hello, I am developping a file browser bu use of internet explorer. I am already so far that I get a full list of all the files of a selected directory. However, I only want to display...
23
2358
by: Mark Tranchant | last post by:
A new project: http://step-by-step.org.uk/ Don't worry about the links yet, the content hasn't been written. I'm just interested in the introduction screen, which is my first attempt at an...
2
3494
by: David Fickbohm | last post by:
People, I am trying to determine the creation date of files in a folder. I am using the following code to find the folder and confirm that files exist in the folder. If someone could give me an...
3
3146
by: Shapper | last post by:
Hello, I created a script to upload a file. To determine the file type I am using userPostedFile.ContentType. For example, for a png image I get "image/png". My questions are: 1. Where can...
3
1697
by: srijan2005 | last post by:
can any one plz help me to use mime type in php....there should be included mime_content_type( ) function...i want to upload a picture like .jpg,.jpeg,.gif extension....when i will upload the picture...
0
2613
by: rautsmita | last post by:
hello friends , i am using to jdk6 and JAXB2.0, i have geomtry.xsd file i am trying to compile this file using jaxb but i got some error i.e.The particle of the type is not a valid restriction of...
2
2355
by: amanzour | last post by:
How can I check the file extension of let say a file extension in the client machine? I am using ASP.NET C# language, and was hoping one of the field validators could take care of my q. but don't...
2
1708
by: Fareast Adam | last post by:
Anybody please help me! The function always return false although file extension is supported. Here my code; function checkExtension($extension) { $valid_ext =...
1
3844
by: Chris Rebert | last post by:
On Sat, Sep 27, 2008 at 3:42 PM, Michael Crute <mcrute@gmail.comwrote: Looking at the docs for the mimetypes module, it just guesses based on the filename (and extension), not the actual contents...
0
6980
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7192
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7364
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5452
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4886
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3087
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1397
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
282
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.