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

How to get the filename for upload file when user select the file?

109 100+
Hi..

I am trying to create a perl-cgi script to make a upload page such that when the user select a file using the "Browse" button, the filename will appear on another textbox.

i understand that will need to include the following in the upload form..

<input type="file" name="datafile" id="datafile" size="40" onchange="javascript: checkfilename();">

i got no idea how to get the filename.. i know that i can do that using ActiveXObject but i dun want to use that option. I want it to be able to be used in ie and mozilla... window or linux os.

Anybody got any idea?
May 21 '07 #1
5 6799
acoder
16,027 Expert Mod 8TB
Assuming your textbox has an id of "textbox" (very original), the following code should work:
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("textbox").value=document.getElementById("datafile").value;
May 21 '07 #2
skyy
109 100+
Assuming your textbox has an id of "textbox" (very original), the following code should work:
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("textbox").value=document.getElementById("datafile").value;
That will give me the full path name together with the filename.

I only want the filename. such as test.txt rather than c:\testfolder\test.txt
May 22 '07 #3
sumittyagi
202 Expert 100+
That will give me the full path name together with the filename.

I only want the filename. such as test.txt rather than c:\testfolder\test.txt
var filePath = document.getElementById("datafile").value;
var fileName = filePath.substring(filePath.lastIndexOf("\\")+1);

Now you have both. filepath and filename, use whatever you want.
May 22 '07 #4
skyy
109 100+
var filePath = document.getElementById("datafile").value;
var fileName = filePath.substring(filePath.lastIndexOf("\\")+1);

Now you have both. filepath and filename, use whatever you want.
Hi thanks for the reply...

Actually i was thinking if there is any other way of getting the filename. I had used the method u mention above but i cant get it to work. Am using the same code as u given.

Seems like i am haing problem with the lastIndexOf("\\") part. it seems that it cant check for the \ character in the string. Is it got to do with java version?
it gives be error: object expected.
May 22 '07 #5
skyy
109 100+
Hi.. i did some testing and found that when i change the element for the lastIndexOf() function, the error disappear. example:

var fileName = filePath.substring(filePath.lastIndexOf("\/")+1);

this will look for the / character instead of the \ character. It does not give me any error. However when i change to \ character, error occurs.

Error: Obect expeected

Anybody got any solution?
May 22 '07 #6

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

Similar topics

5
by: Ariel Dolan | last post by:
Can I use HtmlInputFile to only get the selected file name but not actually upload the file? Clicking the control's Browse button let's the user select a file. All I need is the HtmlInputFile...
3
by: Bijoy Naick | last post by:
I've written a simple file upload user control in VB .NET. It comprises of an InputFile HTML Server Control, an Upload button and a message label. User clicks on the Browse button of the...
3
by: Pitcairnia | last post by:
The basic purpose of the site is for authenticated users to post event listings, which often include photographs. The user is faced with a page where they can insert all of the information about...
3
by: UJ | last post by:
How can I add a browse button to my asp.net page? What I need is a button they can press that will then let them select the file to upload to the server. And if anybody has any good code on how...
15
by: Larry Bud | last post by:
I rarely crosspost, but this affects both ASP and Javascript REALLY odd bug that I ran across in ASP 3.0. I have an input type of file, user clicks browse, then places his cursor in the...
6
by: Reggie | last post by:
am trying to associate username with filename in a upload script. I get this error: Parse error: syntax error, unexpected T_STRING in /home/fhlinux169/c/ clashoff.co.uk/user/htdocs/upload.php...
12
by: GuangXiN | last post by:
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"...
8
johngault
by: johngault | last post by:
I've been working with this PHP page for several days now and I'm stumped. The page is supposed to allow the user to upload up to six images for their profile. When the user adds an image it (the...
1
by: chennaibala | last post by:
can any one send me mutiple image upload program and save the file name with extension in mysql table.we must cheak uploaded file type like bmp or any image file while uploading. i develop...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.