FreeASPUpload tweak

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

I require help tweaking freeASPUpload (http://www.freeaspupload.net).  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

David H.H.Lee earned 159 total points
ID: 23718995
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

sybe earned 156 total points
ID: 23719570
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.


Author Comment

ID: 23719660
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 informatio…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Suggested Courses

621 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