472,325 Members | 1,447 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Can't Get Full Path From File Element

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.file.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.file.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.

Nov 14 '06 #1
5 4138
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.file.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.file.value;
var re = /.+\.(bmp|jpg)$/i;
return re.test(fileName);

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

Nov 14 '06 #2
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.file.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.file.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.file.value;
var re = /.+\.(bmp|jpg)$/i;
return re.test(fileName);

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
Nov 14 '06 #3
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.file.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

Nov 14 '06 #4


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.file.value;
alert(fileName)
if you selected a file e:\test.html then in IE7 alert msg shows only
test.html not e:\test.htmlThen 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

Nov 14 '06 #5
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.file.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.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 14 '06 #6

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

Similar topics

12
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>)....
70
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...
3
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...
18
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...
6
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...
10
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...
2
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...
13
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...
3
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...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.