FreeASPUpload tweak

Posted on 2009-02-23
Last Modified: 2012-05-06

I require help tweaking freeASPUpload (  I have modified the script so that files are not overwritten should they exist already. However, in an ideal world the user would be presented with some kind of message, asking if they wanted to proceed with the upload or not. Is this possible?
Public Sub Save(path)


		Dim streamFile, fileItem, fs

		if Right(path, 1) <> "\" then path = path & "\"

		if not uploadedYet then Upload

        	set fs = Server.CreateObject("Scripting.FileSystemObject")    

		For Each fileItem In UploadedFiles.Items		    


                	myFileName = fileItem.FileName

		        myTempFileName = session("brandSession") & "-" & fileItem.FileName


		        if fs.FileExists(path & myTempFileName) then		    


                    		response.write(myFileName & " exists.")




			        Set streamFile = Server.CreateObject("ADODB.Stream")

			        streamFile.Type = 1


			        StreamRequest.Position = fileItem.Start

			        StreamRequest.CopyTo streamFile, fileItem.Length

			        streamFile.SaveToFile path & myTempFileName, 2


			        Set streamFile = Nothing

			        fileItem.Path = path & myTempFileName		    


			        response.write(myFileName & " uploaded successfully.")	


                	end if		




	End Sub

Open in new window

Question by:lunchboxbill
    LVL 29

    Accepted Solution

    Hi lunchboxbill,
    >>..asking if they wanted to proceed with the upload or not. Is this possible?
    Yes, it's possible. It depend how you control the upload logic there. I've stimulated one sample regarding the mentioned. You can modify it based on your live senario.

    function CheckUpload(){
     var blnUpload=false;
     blnUpload=confirm('Are you sure want to proceed?');


    if (Request("hidVal")="1") then
      Save(YOURPATH)'modify your code here
      Response.write("not Submit")
    end if

    <form id='f1' action="main.asp">
    <input type=hidden id="hidVal" name="hidVal">
    <input type="button" value=" Upload " onClick="javascript:CheckUpload();return false;">
    LVL 28

    Assisted Solution

    Depends on what your definition of 'proceed' is.

    Basically, once a user hit the submit button, everything is posted, including the file, and only when the posted data have completely arrived on the server, you can start checking if there is a file with the same name already present.

    Now you can do two things:
    1. Do nothing, but go back to the user and ask if he's sure to overwrite an existing file. The consequence is however that user has to submit everything again.
    2. Store the file with a temporary filename and then go back to the user. If the user says it is ok to overwrite the file, then on the server delete the old file and rename the file with the temporary name. If the user is not ok, then delete the temporary file. The problem comes when the user does not answer (which will happen now and then), so you end up with a bunch of temporary files. Some day you'll have to delete them.

    Anyway. My solution would be to prevent that there is unclarity about overwriting files beforehand. The user should decide before uploading if the file should be overwritten. That requires maybe a bit of different setup of your application, but it is very well possible.

    LVL 1

    Author Comment

    Thanks for the info guys. I have a solution now where if the file exists on the server, a response is sent back down to the client. the user then clicks if they want to proceed or not, and if so, the script is run again this time with a differnt parameter so the file is overwritten.

    As both of your responses were suitable, i will split the points. apologies its not many points, its all i had left!

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
    I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now