SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2004
    Location
    Cambs
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Help: Free ASP Upload

    Hi Guys

    Right I am using the Free ASP Upload script from http://www.freeaspupload.net/ but I am absolutly stumped as to how I can automatically insert the filename of the file I have uploaded into a table in an access database.

    Can someone suggest some code that I can use with this script to acheive this?

    <%


    ' ****************************************************
    ' Change the value of the variable below to the pathname
    ' of a directory with write permissions, for example "C:\Inetpub\wwwroot"
    Dim uploadsDirVar
    uploadsDirVar = "d:\www\"
    ' ****************************************************

    ' Note: this file uploadTester.asp is just an example to demonstrate
    ' the capabilities of the freeASPUpload.asp class. There are no plans
    ' to add any new features to uploadTester.asp itself. Feel free to add
    ' your own code. If you are building a content management system, you
    ' may also want to consider this script: http://www.webfilebrowser.com/

    function OutputForm()
    %>
    <form name="frmSend" method="POST" enctype="multipart/form-data" action="uploadlink.asp" onSubmit="return onSubmitForm();">
    File 1: <input name=attach1 type=file size=35><br>
    <br>
    <input type=submit value="Upload">
    </form>
    <%
    end function

    function TestEnvironment()
    Dim fso, fileName, testFile, streamTest
    TestEnvironment = ""
    Set fso = Server.CreateObject("Scripting.FileSystemObject")
    if not fso.FolderExists(uploadsDirVar) then
    TestEnvironment = "<B>Folder " & uploadsDirVar & " does not exist.</B><br>The value of your uploadsDirVar is incorrect. Open uploadTester.asp in an editor and change the value of uploadsDirVar to the pathname of a directory with write permissions."
    exit function
    end if
    fileName = uploadsDirVar & "\test.txt"
    on error resume next
    Set testFile = fso.CreateTextFile(fileName, true)
    If Err.Number<>0 then
    TestEnvironment = "<B>Folder " & uploadsDirVar & " does not have write permissions.</B><br>The value of your uploadsDirVar is incorrect. Open uploadTester.asp in an editor and change the value of uploadsDirVar to the pathname of a directory with write permissions."
    exit function
    end if
    Err.Clear
    testFile.Close
    fso.DeleteFile(fileName)
    If Err.Number<>0 then
    TestEnvironment = "<B>Folder " & uploadsDirVar & " does not have delete permissions</B>, although it does have write permissions.<br>Change the permissions for IUSR_<I>computername</I> on this folder."
    exit function
    end if
    Err.Clear
    Set streamTest = Server.CreateObject("ADODB.Stream")
    If Err.Number<>0 then
    TestEnvironment = "<B>The ADODB object <I>Stream</I> is not available in your server.</B><br>Check the Requirements page for information about upgrading your ADODB libraries."
    exit function
    end if
    Set streamTest = Nothing
    end function

    function SaveFiles
    Dim Upload, fileName, fileSize, ks, i, fileKey

    Set Upload = New FreeASPUpload
    Upload.Save(uploadsDirVar)

    ' If something fails inside the script, but the exception is handled
    If Err.Number<>0 then Exit function

    SaveFiles = ""
    ks = Upload.UploadedFiles.keys
    if (UBound(ks) <> -1) then
    SaveFiles = "<B>Files uploaded/B> "
    for each fileKey in Upload.UploadedFiles.keys
    SaveFiles = SaveFiles & Upload.UploadedFiles(fileKey).FileName & " (" & Upload.UploadedFiles(fileKey).Length & "B) "
    next
    else
    SaveFiles = "The file name specified in the upload form does not correspond to a valid file in the system."
    end if
    end function
    %>

    <script>
    function onSubmitForm() {
    var formDOMObj = document.frmSend;
    if (formDOMObj.attach1.value == "" && formDOMObj.attach2.value == "" && formDOMObj.attach3.value == "" && formDOMObj.attach4.value == "" )
    alert("Please press the browse button and pick a file.")
    else
    return true;
    return false;
    }
    </script>


    <%
    Dim diagnostics
    if Request.ServerVariables("REQUEST_METHOD") <> "POST" then
    diagnostics = TestEnvironment()
    if diagnostics<>"" then
    response.write "<div style=""margin-left:20; margin-top:30; margin-right:30; margin-bottom:30;"">"
    response.write diagnostics
    response.write "<p>After you correct this problem, reload the page."
    response.write "</div>"
    else
    OutputForm()
    end if
    else
    OutputForm()
    response.write SaveFiles()
    response.write "<br><br>"
    end if

    %>

  2. #2
    Original Gangster silver trophy Thing's Avatar
    Join Date
    Oct 2000
    Location
    Philadelphia, PA
    Posts
    4,708
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Right here is where your file is saved:

    Code:
    Upload.Save(uploadsDirVar)
    
    	' If something fails inside the script, but the exception is handled
    	If Err.Number<>0 then Exit function
    
        SaveFiles = ""
        ks = Upload.UploadedFiles.keys
        if (UBound(ks) <> -1) then
    SaveFiles = "<B>Files uploaded</B> "
            for each fileKey in Upload.UploadedFiles.keys
    SaveFiles = SaveFiles & Upload.UploadedFiles(fileKey).FileName & " (" & Upload.UploadedFiles(fileKey).Length & "B) "
             next
    So right in the FOR NEXT loop you could add code to insert the values into your database.

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is a easy upload Script with JavaScritp - SWFUpload. I believed that you can very relaxed use it.
    ------------------
    SWFUpload is a small JavaScript/Flash library to get the best of both worlds. It features the great upload capabilities of Flash and the accessibility and ease of HTML/CSS.

    http://code.google.com/p/swfupload/downloads/list
    Tibet - information about the Tibet.
    Plan aTibet Travel Packages by train in July 2010!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •