Solved

Click and Submit without clicking buttons

Posted on 2006-06-21
16
373 Views
Last Modified: 2008-01-09
I want to grab a file and sends it to the server without actually clicking submit button.

For example: if you run this HTML code. It says browse  and lets you select a file and we have to click submit button manually.

I was wondering if we can do the same functionality without clicking any button.
In other words: 1) instead of using browse button and selecting a file:::: grab the file which we already know and where it is located.
                        2)After selecting the file, instead of submit button    :::: programmatically clicks the submit button.

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
<html>
<head><title>Upload Test - 1 File</title></head>

<body>

<form name="Page_Load" method="post" enctype="multipart/form-data"
      action="http://myServer/uploadMedia.aspx"/>

<table>
<tr><td>JPG File</td><td><input type="file" name="jpg file"></td></tr>

<tr><td colspan="2" align="right"><input type="Submit" value="Upload"></td></tr>
</table>

</form>

</body>
</html>
///////////////////////////////////////////////////////////////////////////////////////////////////////////////


It would be a great if you guys could help me in any way.

Praj

0
Comment
Question by:velosumdev
  • 7
  • 5
  • 3
  • +1
16 Comments
 
LVL 12

Expert Comment

by:jessegivy
ID: 16955185
Hmmm, you're gonna have to do something different if you want to select the file from a predetermined location automatically as the input type="file" control doesn't allow for modification of the value attribute, but if you have the location already then you don't need a multipartformdata enctype, and can just pass the string that represents the file path.  Anyway, if you do want the user to select the file and then have it automatically submit after file has been selected try this JS snippet:

<html>
<head><title>Upload Test - 1 File</title>
</head>

<body>

<form name="Page_Load" method="post" enctype="multipart/form-data"
     action="http://myServer/uploadMedia.aspx"/>

<table>
<tr><td>JPG File</td><td><input type="file" name="jpg_file" onChange="document.Page_Load.submit();"></td></tr>
</table>

</form>

</body>
</html>

Please note that I've added an undersocre in the name attribute for your file upload control (jpg_file) spaces in names are not a good idea.

Cheers,

JGI
0
 

Author Comment

by:velosumdev
ID: 16956167
JGI,
   It works without clicking the submit button. Thank you very much for that.

But I also need to find a way to select a file without selecting it by going through the browse button.

Thanks for your help anyway.
0
 
LVL 12

Expert Comment

by:jessegivy
ID: 16956734
This is accomplished on the server side.  Where are you getting the path of said file from?  Like I said there isn't any way to set the value attribute of the input type=file control so you've gotta do it another way.  If the user isn't browsing for the file then were is it coming from?  The database?  If you already have the path of the file then there really isn't any reason for this form at all?  I guess I'm confused.

But yea, you're welcome.  Just explain the issue a little further and I'm sure I can lend a hand :)
0
 

Author Comment

by:velosumdev
ID: 16960953
Thanks for your help again. Here is my issue.

I am writing a J2ME application where our dev. team thinks it would be really handy if we could make a webpage, upon navigating that webpage, it will grab a file and sends it automatically.

So, for example, if I type www.cnn.com and hit enter, it should automatically grabs a file and sends it to the server.
       In this process- I know where my file is, what type of file it is supposed to grab.
                              It knows where to send it.


Please let me know if you still do not understand it. Please free to do that. I am more than happy to explain it more.

Praj
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 16962220
Hi Praj,

I think you are going to run into major security issues with that.  The browsers themselves should not allow this kind of behavior as well as security software.

Just $0.02.  I'd be interested to see how Jess(niper)e would get around that.

J
0
 
LVL 12

Expert Comment

by:jessegivy
ID: 16962602
>>I know where my file is, what type of file it is supposed to grab.
So, the file is currently stored on the server, or somewhere on the www?

>>It knows where to send it.
Where?  Are ya opening this file in the browser?  I'm still a bit uncertain about what you're trying to accomplish.  From your first statement above it implies that you've already got the file, so why would you need to send it somewhere?  Are you emailing it to someone?  What function does this page perform?  Why and where are you sending this file?  I'm still just not sure what the point is.  Will page redirect after submit?  What page are you submitting to, and what's going to be done with this file that can't be accomplished by going there directly seeing as how you've already got the file location?

I thought you had me there Jas(niper)on.  There's no security issue if I'm understanding correctly.  The file is predetermined, so no uploading should be neccessary?  All operations will happen with file object on the server side.
0
 
LVL 12

Expert Comment

by:jessegivy
ID: 16962607
...what sever side scripting language are you using if any?
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 16962656
Jesse,

Just because the file is predetermined doesn't mean the security isn't an issue.  What if we are predeterming that the file is the system registry or a password file?

"So, for example, if I type www.cnn.com and hit enter, it should automatically grabs a file and sends it to the server. "
                                                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

My understanding of security is that no browser should allow a silent upload from client to server.  The best you could do is present the file upload box already filled in with the path and filename and then use a onLoad event to click the button.  But I'd be amazed if that is allowed...
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 8

Expert Comment

by:Perl_Diver
ID: 16963564
if you mean grab a file from the client computer, maybe if it's an intranet you can pull it off somehow since you can have much more control over the clients connected to the server, but on the internet I don't think this is possible, definetly a major security issue. If you mean grab a file from the site the person is viewing, it should be possible as long as the file/folder allows access but you wouldn't use a CGI form for that so you must mean get the file from the client computer. If there is a way to prefill a <input type=file> tag with a value I would be interested to know how. I thought the operating system had control over that, not the browser, which is why there is no value attribute of that particular tag.
0
 

Author Comment

by:velosumdev
ID: 16964016
I will try to explain what exactly I wanted to do.

We have a file which we want to send it to the server. It works when we manually select the file from HTML page which is on the development computer. But we need the whole process automated when that HTML page is navigated by the browser.

Forget about the www.cnn.com. I guess that was a bad example. I should have said HTML page which is in my C:/ drive.

Praj
0
 
LVL 12

Expert Comment

by:jessegivy
ID: 16964219
Okay Praj, I think we're getting somewhere.  This is what I was assuming.  My question is:

If you have the file on the development machine, where are you sending this file?  You've already got it!?!? right?  Are you wanting to open this file in the browser?  Is it an html file?  Why can't you just serve it up?  I don't understand why you're trying to use the upload control?  Isn't the development machine the server?

...sorry, still confused.  If this is just a static HTML page then why aren't you storing it on the server and just serving it up like any other page?

@Jason, you're right that's not allowed.  Ya can't modify the value attribute of the input type=file control via script for security reasons.  What he's trying to do I don't believe requires this though, it's NOT coming from the client, it exists on the dev machine???
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 16964390
I can't quite figure it out either.  Praj, can you be really clear about:

1) Where does the file reside when a user first hits the page
2) Where should the file end up when the user requests the page, and
3) Is this Internet or Intranet design?
0
 

Author Comment

by:velosumdev
ID: 16964900
Sorry about the confusion.

Well, file is in my c:\ directory where my html page resides in my development machine.
        I want to send this file in the IIS web service (.aspx, which accepts a file)
        Its the internet.


I will try to present you the full senario with my code snippet.
/////////////////////////////////////////////////////////////
I have a file called FileSendTest.html in my c:\ directory:

Html page location:     c:\FileSendTest.html
What It does        :   user BROWES the file, selects a file....brower automatically sends that file to the web services...("http://myServer/uploadMedia.aspx")  
                               without clicking the submit button.

==================CODE SNIPPET==================
<html>
<head><title>Upload Test - 1 File</title></head>

<body>

<form name="Page_Load" method="post" enctype="multipart/form-data"
      action="http://myServer/uploadMedia.aspx"/>

<table>
<tr><td>JPG File</td><td><input type="file" name="jpg file"></td></tr>

<tr><td colspan="2" align="right"><input type="Submit" value="Upload"></td></tr>
</table>

</form>

</body>
</html>
======================================================

Now, What I want:
         Once user double clicks that html file which is c:\FileSendTest.html it should automatically grabs and sends the file which is in my c:\ directory as well called c:\testPic.jpg to the web service which is in the code (http://myServer/uploadMedia.aspx)

Praj
0
 
LVL 12

Accepted Solution

by:
jessegivy earned 500 total points
ID: 16965076
Is this web service used from another location as well?  I mean, do you have an instance where you'll want to NOT send testPic.jpg to the web service?  I believe based on this new summary that you're overcomplicating things.  testPic.jpg is a file that will eventually reside on myServer with uploadMedia.aspx, am I correct?  Just access the file testPic.jpg from within the uploadMedia.aspx file.  If you do in fact have an instance where you'll not want this to occur you can set a flag and pass it to the asp.net file.  I'm assuming the confusion lies in the fact that you're not the programmer who wrote uploadMedia.aspx?

...the short answer and the one that's appropriate to this TA is that you simply can NOT send a file in this way.  The only slightly longer answer is that you don't need to.  just access it directly in the asp code.  I'm still unclear what you're doing with the jpg image, but whatever it is you'll have no problems just accessing it on the server side like I've been saying all along.
0
 

Author Comment

by:velosumdev
ID: 16970383
How do I directly have an access to the uploadMedia.aspx and send that file automatically?
0
 
LVL 12

Expert Comment

by:jessegivy
ID: 16971957
There isn't any need to "send" the file to uploadMedia.aspx all you need to do is open it up in Visual Studio .NET and add the appropriate code.  Is the page written with Visual Basic or C#?  I might be able to help with Visual basic, or could give pseudo code for C#.  Before I do though, I'll need to know what you're doing with the jpg image?  Is the image eventually going to have some functionality?  Will it be changed?
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now