Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File upload check problem

Status
Not open for further replies.

false420

Programmer
Mar 31, 2005
87
US
I got this script where i upload a file using sa. everything works perfect excpet i cant get it to check if a file exists and if it does then give it a unique name. this code (depending on how its mix-matched) produces 3 kinds of output. either the filename stays and its always overwritten, the rand works but it only will save the tmp file, or the random works only and save the rand gen filename even if it doesnt exist and it wont show the file name on the next page. anyone got any ideas? maybe even if i could just get it to tak a number on each file instead of checking if it exists would suffice. here is code:

YOU CAN SEE WHERE I COMMENTED OUT A FEW PLACES SO I CAN MIX-MATCH CODE

<% Dim upl %>
<% Set upl = Server.CreateObject("SoftArtisans.FileUp") %>
<%Dim upf%>
<% Set upf = CreateObject("SoftArtisans.FileManager") %>
<% upl.Path = "C:\WUtemp" %>

<% if upl.IsEmpty Then %>
<% Else %>
<%

Dim numberr
Dim strNameWOext
Dim strOname
strOname = upl.form("f1").Shortfilename
Dim y
Dim strExt
%>
<% If upf.FileExists(strOname) Then
'--- Generate a random number to append to the filename
Randomize
numberr = cStr(Rnd())

'--- Separate filename from filename extension
y = InStr(strOName,".")
strNameWOext = Left(stroName,y-1)

y = Len(strOName) - y
strExt = Right(strOName,y)

'--- Call SaveAs so a new name can be provided
upl.Form("f1").SaveAs strNameWOext & "_" & _
numberr & "." & strExt
Else
'--- Calling Save preserves original file name
upl.save
Dim fileup
fileup = upl.form("f1").servername

End If
End If %>

<% 'upl.Save %><BR>
<br><br>
<%
'Dim Fileup
'Fileup = upl.Form("f1").ServerName
%>
<% 'end if %>
 
This is no so much a VBScript question as it is a question about the SoftArtisans.FileUp object. You would have the same problem with the object no matter what language.


Do you have documentation for the object?


PS: You can do file uploads in pure VBScript with no need for any type of object. There are free scripts available for this purpose. Search in this and the ASP forum to find links to them if you are interested.
 
coo thanks. how would you go about splitting a file name and then tacking a rand number on it and puting it in a var
 
The thing about the Rnd() function is that it returns a number between 0.0 and 0.999999999999~

So, if you want a number between 1 and 10 you do this:

MyNumber = Fix(10 * Rnd) + 1

The part inside the parenthesis, 10 * Rnd, will actually produce a number between 0 and 9.99999999~

The Fix() function removes the decimal portion leaving you with a number between 0 and 9.

Then you add +1 to get a number between 1 and 10.
 
OK I found the docs for your file upload object... I'll take a look at them and let you know.

First please clarify one thing: Earlier you posted about a error with this object when no file was uploaded. Is this still happening? If so on which line do you get the errror?
 
nah it works with no fiel being uploaded just fine. its just the checking if it exists and putting anither filename on it if it does part that doesnt work now. thanks for you help buddy
 
OK, I think this page will help you a lot:
Check out the properties and methods of the FileUp object. It has a lot of good info.

It looks like there is a property named IsEmpty that will return True if no file was uploaded.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top