?
Solved

FreeASPUpload tweak

Posted on 2009-02-23
3
Medium Priority
?
500 Views
Last Modified: 2012-05-06
Hi,

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.")
                    
                	else
    		        
			        Set streamFile = Server.CreateObject("ADODB.Stream")
			        streamFile.Type = 1
			        streamFile.Open
			        StreamRequest.Position = fileItem.Start
			        StreamRequest.CopyTo streamFile, fileItem.Length
			        streamFile.SaveToFile path & myTempFileName, 2
			        streamFile.close
			        Set streamFile = Nothing
			        fileItem.Path = path & myTempFileName		    
    	    
			        response.write(myFileName & " uploaded successfully.")	
                
                	end if		
                
		Next
		 
	End Sub

Open in new window

0
Comment
Question by:lunchboxbill
3 Comments
 
LVL 29

Accepted Solution

by:
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.


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

 if(blnUpload){
  document.getElementById('hidVal').value='1';
  document.forms[0].submit();
 }
}
</script>

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

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

Assisted Solution

by:sybe
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.

0
 
LVL 1

Author Comment

by:lunchboxbill
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!
0

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