Forum Moderators: open

Message Too Old, No Replies

how to separate the root and filename

How to separate the root and filename?

         

Kaiman

8:23 pm on Apr 29, 2003 (gmt 0)

10+ Year Member



Hi,
I am trying upload files on the server and let other people to able to download the files. I used a very simple upload script. Actually I would like to do a webboard which can upload files and attach them to the topic. Can anyone tell me how to do that? I know the way of just uploading the file, but I don't know how to let others who are viewing the particular topic download the file.

<%
Set ObjUpload = Server.CreateObject("UploadProject.UploadClass")

ObjUpload.Flocation="c:\tmp"
'objupload.Flocation= "c:\upload"
objupload.DoUpload
%>

This is simple, are there others codes? and do I need to keep any database information about the attachment filename or its root.

le_gber

8:48 pm on Apr 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello Kaiman, and Welcome to Webmasterworld [webmasterworld.com].

I don't know if this is the solution but how about zipping the files and associating them with the appropriate message. Zip files gives a popup window by default I think when you click on them.

You should therefore have a database field for the url of the files associated with the message, and have link or image with <a href="<%=myRecordset.myFileToDownloadUrl%>">.

This should allow you to link files to your messages.

Leo

Kaiman

4:06 am on Apr 30, 2003 (gmt 0)

10+ Year Member



<a href="<%=myRecordset.myFileToDownloadUrl%>">.

Thank you very much for answering, I am so glad that people are very active in this website. I am a beginner in asp, so I might not understand things very well. for the code above
"myFileTodownloadUrl" is the field name in the database used for accessing the location of the file right?
I am not sure, otherwise what does this code means?

And
For example, if I upload a file to a topic, I will browse from my computer
c:\mydoc\filename.txt

After i uploaded the file, the location will be in the server
c:\upload\filname.txt

How do I record the target location and its filename so that it could the database field? When others will download the file, they will download from this target in the server.

le_gber

7:25 am on Apr 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



"myFileTodownloadUrl" is the field name in the database used for accessing the location of the file right?

yes

How do I record the target location and its filename so that it could the database field?

Are you using a form to 'post' you messages. if so simply add a formfield for your file's url. check out aspin.com or 4GuysFromRolla.com there's great asp tutorials there.

Leo

Kaiman

6:30 am on May 1, 2003 (gmt 0)

10+ Year Member



This is what I used

<FORM ACTION="UploadReceive.asp" METHOD="POST" ENCTYPE="multipart/form-data">
<INPUT TYPE=FILE NAME="UploadFormName">
<INPUT TYPE="SUBMIT">
</FORM>

add a formfiled is it the
<input type=file name="uploadFormName">?

if i take
Request.Form(uploadFormName) in the UPloadRecieve.asp, it will come out as an url and the filename of the client's computer.(eg. c:\mydocs\text.txt) How do I retrieve the filename? I try to look in some aspin 's script they are in VB and I m not very familiar to that.

I try to use
-----
Dim filelocation
Dim name
filepath = Request.Form(uploadFormName)
Set fs= Server.CreateObject("Scripting.FileSystemObject")
Set myFile=fs.GetFile(filePath)
name = myFile.Name
------
the line filepath normally is
filepath = "c:\test.txt"

How to I get the double quote there. If I put
filepath = "Request.Form(uploadFormName)"
it will be error

And I am not sure this server.CreateObject will get the filename from the client's computer. If not, then
what about Client.CreateObject?

Please suggest something for me. I really want to get this job done. The main problem is getting the filename.

le_gber

9:09 am on May 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I know that php is really easy to use to upload files (don't know about asp though) so here is a tutorial: [developerfusion.com...]

One question now how do you create your posts on your webboard? are you using a form that fills a database? If yes:

  • add a form field to this form to store the complete filename of the downloadable file
  • put a default value of 'nofile' in this field (will be used later)
  • create another database column to store the filename
  • if you upload all your files to a specific directory add the path to this directory to the script below. add a line to your webboard to dislay an icon to download the file if the value is <> from 'nofile' and put a link on this image like so:

    <%
    Dim FileUrl = MyRecordset.myURLColomns.value
    if FileUrl <> "nofile" then
    Response.Write "<a href='myDirectoryPath/" & MyRecordset.myURLColomns.value &"'><img src='myImageDirectoryPath/myDowloadIcon.gif'></a>"
    else
    Response.Write "><img src='myImageDirectoryPath/myNonDowloadIcon.gif'>"
    end if
    %>

    If anything doesn't work just post another message here (I am not that good with asp ;) )

    Leo

  • Kaiman

    6:25 pm on May 1, 2003 (gmt 0)

    10+ Year Member



    All the thanks to your advices le_gber. I know that php can done uploading pretty easy, but I am editing a source code that is written in asp. I found out that there was a way to get the filename in the original source code that I m editing. It is a .cls file written in some language, maybe in VB. This is just the part I wanted to show you, it is inside a function call DoUpload which you will see at the bottom when it is called.

    #1 Find the beginning of the file tag name (UploadFormName)
    intFileTagStart = InStr(strHeadData, "UploadFormName")
    '#2 Find the beginning of the FilePath ('filename=' plus 10 chars)
    intPathNameStart = InStr(intFileTagStart, strHeadData, "filename=") + 10
    '#3 Find the quote at the end of the file name sent by the user
    intFileNameEnd = InStr(intFileTagStart, strHeadData, vbCrLf) - 1
    ' Check if no file name was sent (exit sub for this example)
    If intPathNameStart = intFileNameEnd Then Exit Sub
    '#4 Parse the path name
    strPathName = Mid(strHeadData, intPathNameStart, intFileNameEnd - intPathNameStart)
    '#5 Find the starting position the file name
    For intCount = intFileNameEnd To intPathNameStart Step -1
    If Mid(strHeadData, intCount, 1) = "\" Then
    intFileNameStart = intCount + 1
    Exit For
    End If
    Next
    '#6 Now parse the file name
    strFileName = Mid(strHeadData, intFileNameStart, intFileNameEnd - intFileNameStart)

    In the last one which is no.6 parsing the filename.
    It is getting the filename. How do I use this
    strFileName in this .cls file to show or use in my .asp page?
    This is how the source code call the class's functions, so there should be a way to link the variable strFileNamein the class. Since it is inside the function DoUpload, could i use ObjUpload.DoUpload.strFileName, I can't test it at the server until I am pretty sure about the code :

    <%
    Set ObjUpload = Server.CreateObject("UploadProject.UploadClass")
    ObjUpload.Flocation="c:\tmp"
    'ObjUpload.Flocation="c:\"
    ObjUpload.DoUpload
    %>

    Kaiman

    3:56 am on May 2, 2003 (gmt 0)

    10+ Year Member



    Besides that could you please tell me how to force download?
    this is how I've done,

    rs("url") is where I kept the location of the file

    <a href= <%=rs("url")%>>download</a>

    when I click the link to the url of the file, it shows the image or document instead of downloading.

    Kaiman

    3:58 am on May 2, 2003 (gmt 0)

    10+ Year Member



    Besides that could you please tell me how to force download?
    this is how I've done,

    rs("url") is where I kept the location of the file

    <a href= <%=rs("url")%>>download</a>

    when I click the link to the url of the file, it shows the image or document instead of downloading.

    le_gber

    7:33 am on May 2, 2003 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    to force the download zip your files (will make them faster to download and doawnload them automaticcally - also check your sticky mailbox (top of the page: you have mail)

    leo