Fancy Upload and Classic ASP

I have spent tonight getting FancyUpload using MooTools to work with a Classic ASP upload page instead of a PHP page. The more I do stuff like this, the more I want to switch to PHP. However I did manage to find a way to make it work, so I’d like to share it since I was unable to find anybody else who was successful.

On the ASP side, I used FreeASPupload. I changed the uploadtester.asp page to call the savefiles() function when it loaded and it worked beautifully. The only problem I had was with the fancyupload JavaScript itself. For some reason, I had to add the url property to the JavaScript initialization string. Even though it is supposed to use the action of the containing <form>, I still needed to make this change. But after that, it was perfect. This widget is perfect and nicely written. If you are looking for a nice Ajax/flash upload component, this is it.

UPDATE (3/9/2008) : There seems to be a problem with the latest version of Flash and IE.  Thre is an error javascript error when closing any page that has the flash upload embeded in it.)  I have found a forum discussing it, but no solution.  I may have to ditch the whole thing for another option.

Share this post :

  • peterjhonhansen
    I Don't like this!
  • peterjhonhansen
    i don't like!
  • fox
    finely the asp for all of you :

    create the an .asp file and put this stuff in it
    ====================
    <%@ Language=VBScript %><% Response.Expires = -1 : Server.ScriptTimeout = 600 %><!-- #include file="freeaspupload.asp" --><%
    Dim uploadsDirVar
    uploadsDirVar = Server.MapPath(".")
    Dim Upload, fileName, fileSize, ks, i, fileKey,SaveFiles
    Set Upload = New FreeASPUpload
    Upload.Save(uploadsDirVar)
    SaveFiles = ""
    ks = Upload.UploadedFiles.keys
    if (UBound(ks) -1) then
    for each fileKey in Upload.UploadedFiles.keys
    Response.Write("{""status"":""1"",""name"":"""& Upload.UploadedFiles(fileKey).FileName &"""}")
    next
    Response.End()
    else
    Response.Write("{""status"":""0"",""error"":""Invalid Upload01""}")
    Response.End()
    end if
    %>{"status":"0","error":"Invalid Upload"}
    ==============================
    on the form section set the form action to the asp file
  • MeneerBo
    Fox, thankx for your input. I got it all working but couldnt figure out the response thing. Now it works like a charm and I can start defining the rest of my flow.
  • tlissak
    after realising that the flash post file by file we dont need to loop and the result have to be a valid JSON syntax
    so here is a the currection ive dident tested (ived just modified on live)
    ===================================================
    <%@ Language=VBScript %>
    <% Response.Expires = -1 : Server.ScriptTimeout = 600 %>
    <!-- #include file="freeaspupload.asp" -->
    <%
    Dim uploadsDirVar
    uploadsDirVar = Server.MapPath(".")

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

    Set Upload = New FreeASPUpload

    Upload.Save(uploadsDirVar)
    SaveFiles = ""
    ks = Upload.UploadedFiles.keys
    if (UBound(ks) -1) then
    Response.Write("{""status"":""1"",""name"":"""& Upload.UploadedFiles(0).FileName &"""}")
    Response.End()
    else
    Response.Write("{""status"":""0"",""error"":""Invalid Upload (No file to upload)""}")
    Response.End()
    end if
    %>
  • Ted
    Superb, works like a treat.
    Thanks everyone, especially Fox for that little code snippet.
  • Biu
    Hi
    I have a div with fancy upload with display none, when a put disply block in java a browse button dont work
    any trick?

    thanks
  • thanks man
  • does anyone know how to make the freeaspupload work on a website. it works fine on my local computer but not when i upload it to my site. i change the dir in uploadTester.asp to a relative path for my site but keep getting an error that the dir doesn't exist.

    im sorry to be a pain but i am new to asp =)
  • does any body anywhere have sample code of what was changed in the uploadtester.asp and the fancyupload javascript initialization string???
  • can some one please show me how to use the fancy upload and freeaspupload. i'm new to asp and fabio's post flies right over my head. i need a simple way to use the fancyupload with freeaspupload. please help!!!
  • thanks ...
  • Viure
    If you want to use Persist, I recommend that first use freeaspUpload like the example from Darkentity to upload and then use ASPJpeg to open the file (only images). Then you can use all the tools from PErsist Jpeg .
  • Stewart
    The problem with the upload sending the first file up then not proceeding to the next can be solved by having your ASP upload script write the result:

    Response.Write("{""result"":""success"", ""size"":""Uploaded successfully.""}")

    That is for a successful upload, obviously.

    Check out Fabio's post and search for something that looks like the above code for more on it. Hope this helps.
  • I too am using PersitsASP_Upload and am finding that it does not register that the file has been uploaded completely and does not update the correct Icon or move onto the next file. (Although it does upload the file correctly.)
    Any ideas?
    Pete
  • Ramon
    Fabio Thanks!!! I showed to this my host Server Intellect and they got it running for me!!! Awesome post!
  • Hi, i've a post that teaches how to implement Fancy Upload with ASP in a really easy way.

    Check it out at: http://zend.lojcomm.com.br/entries/tutorial-sta...
  • Darkentity
    This is the asp script I think he was talking about, its from freeASPupload. Just direct your form to this page and it should work. My flash upload is using jquiry and flash.
    http://www.pixeline.be/experiments/jqUploader/ .




    <!-- #include file="uploaderscript.asp" -->
    <%
    Dim uploadsDirVar
    uploadsDirVar = "d:\home\default\mysite\" 'change to your upload folder
    Dim Upload, fileName, fileSize, ks, i, fileKey,SaveFiles

    Set Upload = New FreeASPUpload
    Upload.Save(uploadsDirVar)

    SaveFiles = ""
    ks = Upload.UploadedFiles.keys
    if (UBound(ks) -1) then
    SaveFiles = "Files uploaded: "
    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
    %>
  • Gree
    Hi all,

    I'm using persits asp_upload, and it works great, The only thing is after a succesfull upload, The wrong icon (=failed) is returned. How come?
    [code]
    .....
    On Error Resume Next

    ' Perform upload
    Upload.Save Server.MapPath("/")&"\My_Upload_Folder"

    ' 8 is the number of "File too large" exception
    If Err.Number = 8 Then
    Response.Write "failed"
    Else
    If Err 0 Then
    Response.Write "error"
    Else
    Response.Write "success"
    End If
    End If
    [/code]
  • Gafs
    I've been tried this. But still haven't worked :(. I really appreaciate if someone give me the detail to do this. Thank you so much!
  • Chris
    Hi Ben, I have been looking for a solution as well... would love to see your code examples, mainly your server-side ASP code that handles the receiving end. Thanks in advance!
  • Ben
    Congratulations. Just don't update your flash if your on a windows machine using IE. I had been using it on an intrantet that is exclusively run through IE and I had to remove it becuase of javascript errors that cropped up that seem to be related to the new flash polayer version. See update above.
  • riclinda
    Yeah!!! finally I succeed!! I'm not more friendly with javascript and so I wasn't able to understand immediately your suggestions...
    thanks Ben!!
  • riclinda
    hi Ben!
    I'm too, I'll waiting for some your code's example!!
    I'm too I've tried to add FancyUpload to FreeAspUpload but unsuccessfully...

    thank you a lot
  • I have neglected the blog, but when I get back in town in a week, I will put up the code.
  • Shane
    Amin, I'm trying to do this in CF too. Have you figured out a solution in CF? It would be helpful to see the code change that Ben made in ASP, please.
  • Alx
    Which upload-Components do you use - w3.upload?
  • I am trying to implement Fancy Uploads using classic ASP as we speak. I can't get it working and would love to see your working example.

    Pretty please?
  • Hi Ben,
    only one line of code change? Why you don't post it?

    Please... a sample code!

    ThanX
  • amin
    it would be nice if Ican have this in Coldfusion. I'm newbie in cfm. Converting from php would be hard...PHP sucks to me
  • I just added you to Twitter - the web is such a funny place.

    I've been sitting here for hours converting the FancyUpload over to classic-ASP.

    Would like to see what you've come up with.

    Compare notes?
  • Ben
    I will try to come up with a post having sample code shortly. I just changed one line of the freeASPupload file. I will take a look and see what I can do.
  • Roberto
    One Sample or Code to download ?
    Thx !!!
  • tim
    hi ben no code samples?
blog comments powered by Disqus