472,334 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Get file path and file name of input type="file"

59
alright suppose i have the following.

Expand|Select|Wrap|Line Numbers
  1. <input type="file" name="upload"  />
  2. <input type="text" name="discription"  />
  3. <input type="image" onclick="addFile();" src="images/addfile.jpg" name="add" alt="Add file" />
Here when user clicks add button, it gets added dynamically in to a div. Which all good and nice, i have very well done so.

But here is the problem, on that parent div there are children, children divs contains the input which displays it's file name and hidden div containing file path, and another hidden input containing the description. As user adds files, they keep getting added in a list fashion.

I plan to get process the values through array on the form submission. By the way there is only form on the parent div containing the child divs. not where the file input is.

What i want is that, i want to get the file path in javascript string as well as file name in another string. How can i go on about doing this.

Hope i was clear in explaining it.
Sep 27 '07 #1
5 33881
pbmods
5,821 Expert 4TB
Heya, cssExp.

My recommendation would be to put each set of inputs in its own div:

Expand|Select|Wrap|Line Numbers
  1. <form id="thePfhorm" ... >
  2.     .
  3.     .
  4.     .
  5.     <div id="insertBefore" style="display: none;">&nbsp;</div>
  6. </form>
  7.  
  8. <div style="display: none;">
  9.     <div id="dolly">
  10.         <input type="file" onchange="setInputs(this.parentNode);" ... />
  11.         .
  12.         .
  13.         .
  14.     </div>
  15. </div>
  16.  
Expand|Select|Wrap|Line Numbers
  1. function addFile(  )
  2. {
  3.     var newElement = document.getElementById('dolly').cloneNode(true);
  4.     newElement.id = '';
  5.     document.getElementById('thePfhorm').insertBefore( newElement, document.getElementById('insertBefore') );
  6.     .
  7.     .
  8.     .
  9. }
  10.  
  11. function setInputs( parent )
  12. {
  13.     var inputs = parent.getElementsByTagName('input');
  14.  
  15.     inputs[1].value = inputs[0].value.match( ... );
  16.     .
  17.     .
  18.     .
  19. }
  20.  
Sep 28 '07 #2
cssExp
59
I have very well done the parent and child part, only part was that i needed to get both filepath and filename, but i found out how to do it. I took the file path and from it i extracted the the file name using lastIndexOf("\\") and substring combination. Thanks for all your help.
Sep 28 '07 #3
pbmods
5,821 Expert 4TB
Heya, cssExp.

Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Sep 28 '07 #4
I have very well done the parent and child part, only part was that i needed to get both filepath and filename, but i found out how to do it. I took the file path and from it i extracted the the file name using lastIndexOf("\\") and substring combination. Thanks for all your help.

Hey I am facing a similar problem. Can you tell me how did you solve this issue.
I need to get the file path from the web form and then pass it as a parameter to an external program. How do I fetch the entire path through cgi?
Mar 20 '08 #5
acoder
16,027 Expert Mod 8TB
Hey I am facing a similar problem. Can you tell me how did you solve this issue.
I need to get the file path from the web form and then pass it as a parameter to an external program. How do I fetch the entire path through cgi?
Post your code. You mention cgi. Do you need this on the client-side or the server-side?
Mar 20 '08 #6

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

Similar topics

5
by: Mr Gordonz | last post by:
Hi all, I want to put a button on a page, and when the user clicks it, the standard Windows "Open File" dialogue box opens, and the user can...
1
by: Mark Sandfox | last post by:
Is there a way to restrict the user to only selecting and sending either a ..gif or .jpg. Everything I have read says this option can not be done...
2
by: HVG | last post by:
Hi, does anyone know why using ".click()" on a <INPUT type="file"> control should be a problem? - the html file selction control is on a very...
2
by: IkBenHet | last post by:
Hello, I am uploading a file using this form in ASP.NET. I have also added a simpel textfield: <form runat="server"...
4
by: kevin | last post by:
Hi, I am trying to create a page so the user can browse the network, select a file and have that file name (text) inserted into our sql DB so I can...
2
by: trint | last post by:
With the following code, I get the "message" whether or not there is content in my filefield: function check_file_field() { var file_field =...
1
by: nad2zen | last post by:
Hi All, How to set the path value to file object using javascript. now i am trying to upload the file without using browse button, but i could...
7
by: Tim Slattery | last post by:
I'm trying to handle the onChange event in an <input type="file"> element. In IE, there's no problem: the event fires when a file in the "open" box...
6
by: passionateforjava | last post by:
Hi All, I am using struts application wherein I need to import file for some purpose.I have used input type="file" for the same which goes like:...
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
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
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. ...
2
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: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...

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.