|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I have a form. I need to get the pdf file from the server directory, put the complete URL to the input box and insert it into the DB table.
Code:
<INPUT TYPE='FILE' SIZE='40' NAME='FILE1'>" When I clicked on the browse button, the file string appears like this --> \\server\Inetpub\Web\letters\file.pdf in the input box The way I like it is ---> G:\Web\letters\file.pdf then convert the string to "G:\Web\letters\file.pdf" to -- http://www.website.com/letters/file.pdf This URL will be placed on the web site for users to click on. |
|
#2
|
||||
|
||||
|
The reason it comes back"\\server\file" is because you are probably accessing it through a network place or file share. If you map a drive to the location and then access it thorugh the network drive you will get the results you seek.
I would still recommend not relying on that technique and simply parse the string and reformat as necessary so that you handle both situations (network place or mapped drive)
__________________
mr... mike.rusaw@realpage.com RalPage, Inc. "I have made this letter longer than usual, only because I have not had the time to make it shorter." - Blaise Paschal |
|
#3
|
|||
|
|||
|
Okay, you were right about map drive and network place location.
I agree this technique is not as good if the map drive letter changes. from "G:\Web\letters\file.pdf" to "H:\Web\letters\file.pdf" But how could I parse the string from either network place or mapped drive since the strings are all different? I want to limit only able to browse files from one mapped drive or network place. -->G:\Web\letters\file.pdf or -->\\server\inetpub\Web\letters\file.pdf (they are both in the same location, it just depends on how the file is browse) |
|
#4
|
||||
|
||||
|
This is where the fun comes into play. They are different but there is some information that is common all the time. Forget about where they are different and find where they are the same. (i.e. they are all going to reside on "\Web\SomeDirectory...\SomeFile...". So you'll want to do the following:
1. parse the string looking for "web" and return everything to the end of the string 2. replace the "\" with "/" 3. apply the appropriate http info at the begining ("http://www.website/") then you have a complete new url that is dynamic based on the file which will be unique but the website url prefix always stays the same. |
|
#5
|
||||
|
||||
|
Here is how i would parse the string. It should work for your example on what ever server you choose:
Code:
<INPUT TYPE='FILE' SIZE='40' NAME='mstrFile1'>"
Dim mstrFileURL
mstrFileURL= ("http://" & Request.ServerVariables("SERVER_NAME") & Replace(Mid(mstrFile1, InstrRev(mstrFile1, "Web") + 3), "\", "/"))
Let me know if that helps... |
|
#6
|
|||
|
|||
|
Would you explain what does the number 3 mean in your code? --is this the position of letters of the word "web"?
It's not working on mine, see following Code:
<INPUT TYPE='FILE' SIZE='40' NAME='mstrFile1'>
<% Dim mstrFileURL
mstrFileURL= ("http://" & Request.ServerVariables("SERVER_NAME") & Replace(Mid(mstrFile1, InstrRev(mstrFile1, "abcde") + 5), "\", "/"))
From the code above, the string I got from the input box after selected the file is "H:\abcde\file.pdf", should I be seeing http://.......? The Request.ServerVariables("SERVER_NAME") works fine. But I have a couple addresses on one server like - web.sitename.com - abcde.sitename.com (actual web site reside) The form I have is in web.sitename.com From the form, I only want to browse files in abcde.sitename.com, so the Request.ServerVariables("SERVER_NAME") will end up "http://web.sitename.com" instead of "http://abcde.sitename.com" Sorry, should have mentioned this earlier, I was trying not to confuse people. But thanks a lot for your effort here! |
|
#7
|
||||
|
||||
|
I am getting the following output when i run:
Code:
Dim mstrFileURL
Dim mstrFile1
mstrFile1 = "H:\abcde\file.pdf"
mstrFileURL= ("http://" & Request.ServerVariables("SERVER_NAME") & Replace(Mid(mstrFile1, InstrRev(mstrFile1, "abcde") + 5), "\", "/"))
Response.Write(mstrFileURL)
output: http://localhost/file.pdf |
|
#8
|
||||
|
||||
|
Also the InstrRev returns and integer of the location where the search string is located. The "+3 or +5" adds additional positions for determining what to return as a result. I assumed you did not want to return "Web" so I added 3 ( or 5 in the case of abcde).
|
|
#9
|
|||
|
|||
|
Thanks very much! It works mr.
I moved the following code to another page and leaving this line <INPUT TYPE='FILE' SIZE='40' NAME='mstrFile1'> on the first page Code:
mstrFile1 = request.Form("mstrFile1")
mstrFileURL= ("http://" & Request.ServerVariables("SERVER_NAME") & Replace(Mid(mstrFile1, InstrRev(mstrFile1, "abcde") + 5), "\", "/"))
response.Write mstrFileURL
|
|
#10
|
||||
|
||||
|
Great! I should have been more specific about the <input> tag. I just wanted you to see that you needed to rename the field (or at least make them match) and then you can intercept the requested form variable and since it is a module level string variable i name it "mstr" then "File1".
Good luck. I hope you can help someone else out in the future... |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > Browse files from input type=FILE? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|