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

why file upload cannot work?

I want the file upload element disappear, instead of it, I place a text
box and a button with my own css defination.
but it doesn't work on IE7. What should I do now?
<form action="upload.php" method="POST" enctype="multipart/form-data">
<p>
<span>Select photo:</span>
<input type="file" name="photo" style="display:none;">
<input type="text" name="photoUrl" class="s1" />
<input type="button" class="s2"
onClick="photo.disabled=false;photo.click();photoU rl.value=photo.value;photo.disabled=true"
value="Browse" />
</p>
</form>
Jun 27 '08 #1
12 2448
On Jun 10, 11:31 pm, GuangXiN <xvt...@gmail.comwrote:
I want the file upload element disappear, instead of it, I place a text
box and a button with my own css defination.
but it doesn't work on IE7. What should I do now?
<form action="upload.php" method="POST" enctype="multipart/form-data">
<p>
<span>Select photo:</span>
<input type="file" name="photo" style="display:none;">
<input type="text" name="photoUrl" class="s1" />
<input type="button" class="s2"
onClick="photo.disabled=false;photo.click();photoU rl.value=photo.value;photo.disabled=true"
value="Browse" />
</p>
</form>
turn the button into a anchor you can style that any way you want.
Jun 27 '08 #2
Lu*******@gmail.com wrote:
On Jun 10, 11:31 pm, GuangXiN <xvt...@gmail.comwrote:
>I want the file upload element disappear, instead of it, I place a text
box and a button with my own css defination.
but it doesn't work on IE7. What should I do now?
<form action="upload.php" method="POST" enctype="multipart/form-data">
<p>
<span>Select photo:</span>
<input type="file" name="photo" style="display:none;">
<input type="text" name="photoUrl" class="s1" />
<input type="button" class="s2"
onClick="photo.disabled=false;photo.click();photo Url.value=photo.value;photo.disabled=true"
value="Browse" />
</p>
</form>

turn the button into a anchor you can style that any way you want.
Sorry, what I mean is the file upload element doesn't work.
the file upload element's style cannot be set, so I make it unvisiable,
but so it can't send a correct file upload request to web server.
Jun 27 '08 #3
GuangXiN wrote on 11 jun 2008 in comp.lang.javascript:
Lu*******@gmail.com wrote:
>On Jun 10, 11:31 pm, GuangXiN <xvt...@gmail.comwrote:
>>I want the file upload element disappear, instead of it, I place a
text box and a button with my own css defination.
but it doesn't work on IE7. What should I do now?
<form action="upload.php" method="POST"
enctype="multipart/form-data">
<p>
<span>Select photo:</span>
<input type="file" name="photo" style="display:none;">
<input type="text" name="photoUrl" class="s1" />
<input type="button" class="s2"
onClick="photo.disabled=false;photo.click();phot oUrl.value=photo.valu
e;photo.disabled=true" value="Browse" />
</p>
</form>

turn the button into a anchor you can style that any way you want.

Sorry, what I mean is the file upload element doesn't work.
the file upload element's style cannot be set, so I make it
unvisiable, but so it can't send a correct file upload request to web
server.
"Doesn't work" is not an acceptable fraze in this NG, unless you explain
what and how, what debugging tou did, and if and what errorstring and
linenumbers you encountered.

As a security measure, you cannot manipulate the input file element of html
upload forms. Otherwise it would be too easy to secretly upload another
file than the one shown and so compromize the user's private parts.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 27 '08 #4
Evertjan. wrote:
GuangXiN wrote on 11 jun 2008 in comp.lang.javascript:
>Lu*******@gmail.com wrote:
>>On Jun 10, 11:31 pm, GuangXiN <xvt...@gmail.comwrote:
I want the file upload element disappear, instead of it, I place a
text box and a button with my own css defination.
but it doesn't work on IE7. What should I do now?
<form action="upload.php" method="POST"
enctype="multipart/form-data">
<p>
<span>Select photo:</span>
<input type="file" name="photo" style="display:none;">
<input type="text" name="photoUrl" class="s1" />
<input type="button" class="s2"
onClick="photo.disabled=false;photo.click();pho toUrl.value=photo.valu
e;photo.disabled=true" value="Browse" />
</p>
</form>
turn the button into a anchor you can style that any way you want.
Sorry, what I mean is the file upload element doesn't work.
the file upload element's style cannot be set, so I make it
unvisiable, but so it can't send a correct file upload request to web
server.

"Doesn't work" is not an acceptable fraze in this NG, unless you explain
what and how, what debugging tou did, and if and what errorstring and
linenumbers you encountered.

As a security measure, you cannot manipulate the input file element of html
upload forms. Otherwise it would be too easy to secretly upload another
file than the one shown and so compromize the user's private parts.
OK, let me explain my words.
I wrote a file upload component, but I cannot modify its sytle to what I
want. So I added a textbox and a button with style, and then I make the
file upload component hidden, I want to use script to simulate the file
upload's "Browse" click. I am sure that file select dialog popup when I
click the button. I select a image file, the path and filename did
display in the textbox. But when I click submit, server side script
caught no file.
Jun 27 '08 #5
GuangXiN wrote on 11 jun 2008 in comp.lang.javascript:
>As a security measure, you cannot manipulate the input file element
of html upload forms. Otherwise it would be too easy to secretly
upload another file than the one shown and so compromize the user's
private parts.
OK, let me explain my words.
I wrote a file upload component, but I cannot modify its sytle to what
I want. So I added a textbox and a button with style, and then I make
the file upload component hidden, I want to use script to simulate the
file upload's "Browse" click. I am sure that file select dialog popup
when I click the button. I select a image file, the path and filename
did display in the textbox.
As I said, security could be compromized by that.
The browser does not contemplate your possible good intentions.
But when I click submit, server side script caught no file.
Do serverside scripts catch files? Fire perhaps?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 27 '08 #6
On Jun 11, 11:31*am, GuangXiN <xvt...@gmail.comwrote:
I want the file upload element disappear, instead of it, I place a text
box and a button with my own css defination.
but it doesn't work on IE7. What should I do now?
<form action="upload.php" method="POST" enctype="multipart/form-data">
* *<p>
* * *<span>Select photo:</span>
* * *<input type="file" name="photo" style="display:none;">
* * *<input type="text" name="photoUrl" class="s1" />
* * *<input type="button" class="s2"
onClick="photo.disabled=false;photo.click();photoU rl.value=photo.value;phot*o.disabled=true"
value="Browse" />
* *</p>
</form>
don't use "disabled",only use "display:none";

Jun 27 '08 #7
Evertjan. wrote:
GuangXiN wrote on 11 jun 2008 in comp.lang.javascript:
>>As a security measure, you cannot manipulate the input file element
of html upload forms. Otherwise it would be too easy to secretly
upload another file than the one shown and so compromize the user's
private parts.
OK, let me explain my words.
I wrote a file upload component, but I cannot modify its sytle to what
I want. So I added a textbox and a button with style, and then I make
the file upload component hidden, I want to use script to simulate the
file upload's "Browse" click. I am sure that file select dialog popup
when I click the button. I select a image file, the path and filename
did display in the textbox.

As I said, security could be compromized by that.
The browser does not contemplate your possible good intentions.
Is there any other way to implement what I need? I just need a file
upload component with customs style in css file.
>But when I click submit, server side script caught no file.

Do serverside scripts catch files? Fire perhaps?
PHP has an $_FILES arra. When submit with a file, it will be not null.
I tried to make the file upload component appear and I click the
following button (NOT the Browse button in fileupload component). I can
choose a file and the file upload component show its path correctly.
I click submit and PHP shows that $_FILES is still null.
Jun 27 '08 #8
GuangXiN wrote:
Evertjan. wrote:
>GuangXiN wrote on 11 jun 2008 in comp.lang.javascript:
>>>As a security measure, you cannot manipulate the input file element
of html upload forms. Otherwise it would be too easy to secretly
upload another file than the one shown and so compromize the user's
private parts.

OK, let me explain my words.
I wrote a file upload component, but I cannot modify its sytle to what
I want. So I added a textbox and a button with style, and then I make
the file upload component hidden, I want to use script to simulate the
file upload's "Browse" click. I am sure that file select dialog popup
when I click the button. I select a image file, the path and filename
did display in the textbox.
As I said, security could be compromized by that.
The browser does not contemplate your possible good intentions.
Is there any other way to implement what I need? I just need a file
upload component with customs style in css file.
This is rather a question for comp.infosystems.www.authoring.stylesheets.
But I am pretty sure you will have to live with the fact that a custom style
cannot be applied to this control in all user agents, and I can't think of a
*viable* alternative.
PHP has an $_FILES arra. When submit with a file, it will be not null.
I tried to make the file upload component appear and I click the
following button (NOT the Browse button in fileupload component). I can
choose a file and the file upload component show its path correctly.
I click submit and PHP shows that $_FILES is still null.
Of course. By disabling the file input control you have only caused only
the encoded file path to be submitted per `photoUrl'. A file input control
in a form causes the encoded content of the selected file to be submitted
instead. And if it was possible to set the value of that control with
scripting, any Web site you visit could upload any file from your computed
without your knowing it; you do not want that to happen. (Using
display:none as suggested will not change that.)
PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Jun 27 '08 #9
Thomas 'PointedEars' Lahn wrote:
[snip]
>
Of course. By disabling the file input control you have only caused only
the encoded file path to be submitted per `photoUrl'. A file input control
in a form causes the encoded content of the selected file to be submitted
instead. And if it was possible to set the value of that control with
scripting, any Web site you visit could upload any file from your computed
without your knowing it; you do not want that to happen. (Using
display:none as suggested will not change that.)
Certainly the risk of being able to set the value of a file input
control via a script is clear to those who understand its function.

My interpretation of the OP's request was the following question:

Is it possible to write a script that mimic's a user clicking the upload
box. Nothing nefarious... just some way of opening the Open... dialog
such that the file input control's value will be populated in a
legitimate fashion.

I'd be the first to admit that there may be a heavy does of inference
going on, but if that wasn't the OP's intention, it's certainly where my
musings lead me.

I thought that the click function would do it, but I think all that does
is emulate the user clicking at some random point on the control and not
specifically on the Upload button.

Any thoughts?
Jun 27 '08 #10
Dan Rumney wrote:
Thomas 'PointedEars' Lahn wrote:
>Of course. By disabling the file input control you have only caused only
the encoded file path to be submitted per `photoUrl'. A file input control
in a form causes the encoded content of the selected file to be submitted
instead. And if it was possible to set the value of that control with
scripting, any Web site you visit could upload any file from your computed
without your knowing it; you do not want that to happen. (Using
display:none as suggested will not change that.)

Certainly the risk of being able to set the value of a file input
control via a script is clear to those who understand its function.
I would not be so sure.
My interpretation of the OP's request was the following question:

Is it possible to write a script that mimic's a user clicking the upload
box.
That is assuming that there is always an upload _button_.
Nothing nefarious... just some way of opening the Open... dialog
such that the file input control's value will be populated in a
legitimate fashion.
[...]
I thought that the click function would do it, but I think all that does
is emulate the user clicking at some random point on the control and not
specifically on the Upload button.

Any thoughts?
ISTM the proprietary click() method is available for input[type="file"]
controls but does nothing at all (in Firefox 2.0.0.14/Gecko 1.8.1.14), not
even emulating a random click anywhere within the control's canvas. In
contrast to clicking directly, the `click' event does not occur for this
control when click() is called. However error-prone, it does occur then for
other types of controls.

This might be another security precaution to prevent an attacker from
selecting a file programmatically.
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Jun 27 '08 #11
Thomas 'PointedEars' Lahn wrote:
[snip]
>Certainly the risk of being able to set the value of a file input
control via a script is clear to those who understand its function.

I would not be so sure.
I confess to a little weaselry here. I'd argue that anyone who isn't
aware of this risk doesn't understand its function ;o)
>
>My interpretation of the OP's request was the following question:

Is it possible to write a script that mimic's a user clicking the upload
box.

That is assuming that there is always an upload _button_.
Is your point that a text only browser would have an... well, I'm not
sure what the text-only version of a button is called. But I concede the
point that a button is only the appropriate term for a graphical
representation of the form, but I'm pretty sure my meaning was clear.
>
>Nothing nefarious... just some way of opening the Open... dialog
such that the file input control's value will be populated in a
legitimate fashion.
[...]
I thought that the click function would do it, but I think all that does
is emulate the user clicking at some random point on the control and not
specifically on the Upload button.

Any thoughts?

ISTM the proprietary click() method is available for input[type="file"]
controls but does nothing at all (in Firefox 2.0.0.14/Gecko 1.8.1.14), not
even emulating a random click anywhere within the control's canvas. In
contrast to clicking directly, the `click' event does not occur for this
control when click() is called. However error-prone, it does occur then for
other types of controls.
And wouldn't you know it, it 'works' in MSIE. Personally, I think it's a
shame that there's no way to do this (See below)
This might be another security precaution to prevent an attacker from
selecting a file programmatically.
Granted, but I grow a little tired of 'security precautions'.
I'm not laissez-faire about security, but I get frustrated at imposed
restrictions because there's some chance that somebody somewhere might
be able to do something that needs to be prevented.
It's a no-win argument because the security advocates do not need to
back up their position. They have the trump card which is "security risk"

Slight rant aside, this kind of attack, in my mind, could be more
readily protected against by alerting the user whenever a file is to be
transferred by the UA. The UA knows that it's about to read a local file
(because it's going to have to open a handle to that file) so why not
post a warning, instead of hobbling the functionality of form controls?
Jun 27 '08 #12
Dan Rumney wrote:
Thomas 'PointedEars' Lahn wrote:
[snip]
>>My interpretation of the OP's request was the following question:

Is it possible to write a script that mimic's a user clicking the upload
box.
That is assuming that there is always an upload _button_.

Is your point that a text only browser would have an... [...]
My point is instead that no Web standard says how a file input control is to
be rendered; HTML 4.01 only says what it should allow to do. And that is
good so.
>>Nothing nefarious... just some way of opening the Open... dialog
such that the file input control's value will be populated in a
legitimate fashion.
[...]
I thought that the click function would do it, but I think all that does
is emulate the user clicking at some random point on the control and not
specifically on the Upload button.

Any thoughts?
ISTM the proprietary click() method is available for input[type="file"]
controls but does nothing at all (in Firefox 2.0.0.14/Gecko 1.8.1.14), not
even emulating a random click anywhere within the control's canvas. In
contrast to clicking directly, the `click' event does not occur for this
control when click() is called. However error-prone, it does occur then for
other types of controls.

And wouldn't you know it, it 'works' in MSIE.
True.
Personally, I think it's a shame that there's no way to do this (See below)
>This might be another security precaution to prevent an attacker from
selecting a file programmatically.

Granted, but I grow a little tired of 'security precautions'.
I'm not laissez-faire about security, but I get frustrated at imposed
restrictions because there's some chance that somebody somewhere might
be able to do something that needs to be prevented.
It's a no-win argument because the security advocates do not need to
back up their position. They have the trump card which is "security risk"
I don't think so. For example, recently Gecko established a customizable
few-seconds timeout before a download/install dialog can be confirmed
because otherwise there was the possibility that the user accidentally
executed malicious software when pressing the return key while typing and a
script kiddie had the dialog window pop up. IIRC there was a real case that
prompted this design decision, and I think it is a Good Thing that it was
implemented. (Making the Cancel button the default instead would have been
rather counter-intuitive.)

The same thing could happen with a file upload/select dialog window that
popped up without user interaction.
Slight rant aside, this kind of attack, in my mind, could be more
readily protected against by alerting the user whenever a file is to be
transferred by the UA. The UA knows that it's about to read a local file
(because it's going to have to open a handle to that file) so why not
post a warning, instead of hobbling the functionality of form controls?
Maybe because the probability that a user uses an file upload control on
purpose (maybe without having scripting enabled) is greater than the
probability of a script kiddie wanting to click on it without user interaction.
PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Jun 27 '08 #13

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

Similar topics

20
by: CHIN | last post by:
Hi all.. here s my problem ( maybe some of you saw me on other groups, but i cant find the solution !! ) I have to upload a file to an external site, so, i made a .vbs file , that logins to...
7
by: Joe | last post by:
I have an upload file operation in the web application. UploadForm.asp is the form, and UploadAction.asp is the form processing. //UploadForm.asp <FORM NAME="InputForm"...
1
by: PeterB | last post by:
Hi! I'm using Pure ASP File Upload (http://www.asp101.com/articles/jacob/scriptupload.asp) to upload a file from a client to a server. I am testing both on a local IIS and a remote server. The...
1
by: Chris Fink | last post by:
I am using the html input type=file to upload files to the webserver. This is working fine, but only for files less than ~3mb in size. When I attempt to upload a file >3mb, i immediatley receive a...
3
by: IRAS Blues | last post by:
Hi all, I've got a form that consists of a bunch of textboxes and also file upload inputs. For both sets of fields, I need to be able to add in additional elements on the fly. This is done by an...
2
by: chuckdfoster | last post by:
I have a page that users upload files. Is there a way to restrict the file types that they can upload? thanks, -- Chuck Foster Programmer Analyst Eclipsys Corporation - St. Vincent Health...
18
by: Jen | last post by:
I'm using Microsoft's own VB.NET FTP Example: http://support.microsoft.com/default.aspx?scid=kb;en-us;832679 I can get the program to create directories, change directories, etc., but I can't...
6
by: Marko Vuksanovic | last post by:
I am trying to implement a file upload progress indicator (doesn't have to be a progress bar) using atlas... I do realize that the indicator cannot be implemented using Update panel control, but is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
Oralloy
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,...
0
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
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,...

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.