Dear Friends,
I did a file type validation in Javascript. Just i want to check
whether a selected file is BMP or JPG. I wrote the following function
for it.
function checkType(){
Text = document.frm.fi le.value
if(Text.indexOf (":\\") == 1)
{
if("bmp" == Text.substring( (Text.length - 3), Text.length) || "jpg"
== Text.substring( (Text.length - 3), Text.length))
return true;
}
return false;
}
It is working Fine in IE6 ,Mozilla, Opera but it is not working IE7.
Because in IE7 if i put alert for document.frm.fi le.value it showing
only the file name, not file path (Ex: if i select a file e:\test.zip)
in IE7 it giving only test.zip. But i need the full path e:\test.zip
then only my first if condition will be satisfied. This problem only in
IE7.
Please help me is there any way to overcome this problem? or this is
problem of IE7.
Thanks in advance
Sriram. 5 4213
Smarty wrote:
Dear Friends,
I did a file type validation in Javascript. Just i want to check
whether a selected file is BMP or JPG. I wrote the following function
for it.
function checkType(){
Text = document.frm.fi le.value
Use var to explicitly define the scope of variables, keep them local
unless a global scope is required.
if(Text.indexOf (":\\") == 1)
Why do you care about that?
{
if("bmp" == Text.substring( (Text.length - 3), Text.length) || "jpg"
== Text.substring( (Text.length - 3), Text.length))
return true;
}
return false;
}
Why not:
var fileName = document.frm.fi le.value;
var re = /.+\.(bmp|jpg)$/i;
return re.test(fileNam e);
Note that:
- filenames ending in .bmp or .jpg are not reliable indicators of the
actual format of the content;
- files might also fit the criteria for JPEG or bitmap even if they
have other extensions, such as .jpeg or .raw (or whatever else a user
might have specified) or no extension at all.
GIF and TIFF image formats are also popular, are you certain you want
to exclude them (just a question...)?
--
Rob
Dear Rob,
Thanks for your reply. But i think you didnt get core of my doubt. Your
method and my method works in all browser except IE7 because
var fileName = document.frm.fi le.value;
alert(fileName)
if you selected a file e:\test.html then in IE7 alert msg shows only
test.html not e:\test.html
Thats is the main problem. Also one more thing in your example, if i
just type test.bmp with out selecting through browse button you method
wont work, bec u checking only the extension. We want to check the full
path
We just take this problem in the way how to make it work in IE7.
Thanks
Sriram
On Nov 14, 12:36 pm, "RobG" <r...@iinet.net .auwrote:
Smarty wrote:
Dear Friends,
I did a file type validation in Javascript. Just i want to check
whether a selected file is BMP or JPG. I wrote the following function
for it.
function checkType(){
Text = document.frm.fi le.valueUse var to explicitly define the scope of variables, keep them local
unless a global scope is required.
if(Text.indexOf (":\\") == 1)Why do you care about that?
{
if("bmp" == Text.substring( (Text.length - 3), Text.length) || "jpg"
== Text.substring( (Text.length - 3), Text.length))
return true;
}
return false;
}Why not:
var fileName = document.frm.fi le.value;
var re = /.+\.(bmp|jpg)$/i;
return re.test(fileNam e);
Note that:
- filenames ending in .bmp or .jpg are not reliable indicators of the
actual format of the content;
- files might also fit the criteria for JPEG or bitmap even if they
have other extensions, such as .jpeg or .raw (or whatever else a user
might have specified) or no extension at all.
GIF and TIFF image formats are also popular, are you certain you want
to exclude them (just a question...)?
--
Rob
Smarty wrote:
Dear Rob,
Please don't top-post, reply below trimmed quotes.
>
Thanks for your reply. But i think you didnt get core of my doubt. Your
method and my method works in all browser except IE7 because
Your method fails in Safari and Firefox on Mac at least, where the
filename below will be returned as "/test.html" - note the lack of
protocol.
>
var fileName = document.frm.fi le.value;
alert(fileName)
if you selected a file e:\test.html then in IE7 alert msg shows only
test.html not e:\test.html
Then my method "works" in IE 7 too (sorry, I don't have it available
for testing) since it only cares about the last 5 characters of the
filename.
>
Thats is the main problem. Also one more thing in your example, if i
just type test.bmp with out selecting through browse button you method
wont work, bec u checking only the extension. We want to check the full
path
If you start from the premise that you can't reliably test the filename
using client-side script (assuming we are talking about a web
application) then you are on the right track. For your "test", I can
enter blah://blah.jpg and you'll think you've got a valid filename.
You can't test if the filename entered actually exists or if it is the
right type, all you can do is look at the extension and if it's not one
you like, suggest the user check it and, if necessary, try again. Let
them submit whatever they want and let the server sort it out.
>
We just take this problem in the way how to make it work in IE7.
No doubt there is a security setting somewhere to let you see the full
filename, but is that a reasonable solution? Will it really help?
--
Rob
On Nov 14, 2:04 pm, "RobG" <r...@iinet.net .auwrote:
Smarty wrote:
Dear Rob,Please don't top-post, reply below trimmed quotes.
Thanks for your reply. But i think you didnt get core of my doubt. Your
method and my method works in all browser except IE7 becauseYour method fails in Safari and Firefox on Mac at least, where the
filename below will be returned as "/test.html" - note the lack of
protocol.
var fileName = document.frm.fi le.value;
alert(fileName)
if you selected a file e:\test.html then in IE7 alert msg shows only
test.html not e:\test.htmlThe n my method "works" in IE 7 too (sorry, I don't have it available
for testing) since it only cares about the last 5 characters of the
filename.
Thats is the main problem. Also one more thing in your example, if i
just type test.bmp with out selecting through browse button you method
wont work, bec u checking only the extension. We want to check the full
pathIf you start from the premise that you can't reliably test the filename
using client-side script (assuming we are talking about a web
application) then you are on the right track. For your "test", I can
enter blah://blah.jpg and you'll think you've got a valid filename.
You can't test if the filename entered actually exists or if it is the
right type, all you can do is look at the extension and if it's not one
you like, suggest the user check it and, if necessary, try again. Let
them submit whatever they want and let the server sort it out.
We just take this problem in the way how to make it work in IE7.No doubt there is a security setting somewhere to let you see the full
filename, but is that a reasonable solution? Will it really help?
--
Rob
Dear Rob,
Thanks for your reply. Yes you are right, user can cheat us any way,
only way is server side validation. I am going to check only the file
extension.
Take Care,
Sriram
RobG said the following on 11/14/2006 4:04 AM:
Smarty wrote:
>Dear Rob,
Please don't top-post, reply below trimmed quotes.
>Thanks for your reply. But i think you didnt get core of my doubt. Your method and my method works in all browser except IE7 because
Your method fails in Safari and Firefox on Mac at least, where the
filename below will be returned as "/test.html" - note the lack of
protocol.
>var fileName = document.frm.fi le.value; alert(fileName )
if you selected a file e:\test.html then in IE7 alert msg shows only test.html not e:\test.html
Then my method "works" in IE 7 too (sorry, I don't have it available
for testing) since it only cares about the last 5 characters of the
filename.
It does "work" in IE7.
>We just take this problem in the way how to make it work in IE7.
No doubt there is a security setting somewhere to let you see the full
filename, but is that a reasonable solution? Will it really help?
There is no setting in IE7 to expose the full path name as MS rightfully
decided you didn't need to know the full path. The only benefit the full
path will give anybody is to be able to potentially see the file
structure of the HD it is on.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Richard Hanson |
last post by:
Over the last few days, I reinstalled Win2kSP2 to a spare harddrive I
had just swapped into my Fujitsu LifeBook P1120 (long story <wink>).
Subsequently, I DL'ed the newest Python alpha (2.4a2), and when trying
to install it, I immediately got this error:
This installation package cannot be installed by the
Windows Installer service. You must install a
Windows service pack that contains a newer version
of the Windows Installer service.
|
by: Michael Hoffman |
last post by:
Many of you are familiar with Jason Orendorff's path module
<http://www.jorendorff.com/articles/python/path/>, which is frequently
recommended here on c.l.p. I submitted an RFE to add it to the Python
standard library, and Reinhold Birkenfeld started a discussion on it in
python-dev
<http://mail.python.org/pipermail/python-dev/2005-June/054438.html>.
The upshot of the discussion was that many python-dev'ers wanted path
added to the...
|
by: Xah Lee |
last post by:
Split File Fullpath Into Parts
Xah Lee, 20051016
Often, we are given a file fullpath and we need to split it into the
directory name and file name. The file name is often split into a core
part and a extension part. For example:
'/Users/t/web/perl-python/I_Love_You.html'
becomes
|
by: Keith Brown |
last post by:
I have an application that allows embedded storage of ANY chosen file
in an OLE field. The file could have been dragged-and-dropped into
the field or it might have been selected and imported programmatically
using the common file dialog. Regardless, I need to determine the
filetype/extension of each of these files already stored in my OLE
fields and display it for the user.
Double-clicking the raw OLE field or using the
.Verb =...
|
by: scottyman |
last post by:
I can't make this script work properly. I've gone as far as I can with
it and the rest is out of my ability. I can do some html editing but
I'm lost in the Java world. The script at the bottom of the html page
controls the form fields that are required. It doesn't function like
it's supposed to and I can leave all the fields blank and it still
submits the form. Also I can't get it to transfer the file in the
upload section. The file name...
| |
by: Paul Cheetham |
last post by:
Hi,
I am developing an application that needs to store some machine-specific
settings. The application is going to be published on the network in
order to keep the clients on the latest version.
Because of this, I am unable to store these settings in the App.Config
file, as this gets updated every time the application does, and there
doesn't appear to be a way of preventing this.
Most of my application settings are kept in the...
|
by: Sridhar |
last post by:
Hi,
I have a web form where it has a <input type=file id=file1> control. I
have an Upload button to upload the file. WHen I click on browse and select
one file, it is showing the full file path in the text box of File control.
But in the code behind when I try to get the FullFile path using
file1.PostedFile.FilePath it is not giving the full path (c:\test\test.pdf).
Instead it is giving only file name (test.pdf). If i try to do this on...
|
by: Rick |
last post by:
The following code will enter an infinate loop when in ReadChars. I can only
make it happen when reading a Stream and with this particular XML. If I use
the ReadInnerXml call rather than my own ReadElementBodyAsXml the code works,
but is less efficent. ReadElementBodyAsXml is required by my application
with .Net Framework 1.1.
The code breaks on the second call to ReadElementBodyAsXml with the inner xml:
</EGDConfigExtension>...
|
by: forest demon |
last post by:
for example, let's say I do something like,
System.Diagnostics.Process.Start("notepad.exe","sample.txt");
if the user does a SaveAs (in notepad), how can i capture the path that
the user selects?
thanks...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |