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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SoftArtisans FileUP to upload files

Status
Not open for further replies.

snix1

Programmer
Dec 12, 2000
107
0
0
US
Hi! I'm using SoftArtisans FileUP to upload ASP files and have a problem which is driving me nuts. I have a form in which users enter a bunch of data and then can choose up either upload a file or enter data in a TEXTAREA field. My action page needs to check whether a file name was entered in the file field: <input type=&quot;file&quot; name=&quot;f1&quot;>. If so, then I want to upload the file to a specific directory, get the filename and store the filename in the database. If they just fill out the textarea, then just store that in the database and nothing is uploaded.

If I check if the file is not there, it does not upload although no error is generated. I have a small script which shows the problem:

Code:
<HTML>
	<HEAD>
	<TITLE>Please Upload Your File</TITLE>
	</HEAD>
	<BODY>
	<form enctype=&quot;multipart/form-data&quot; method=&quot;post&quot; action=&quot;simple2.asp&quot;>
	Enter filename to upload: <input type=&quot;file&quot; name=&quot;f1&quot;><br>
	<input type=&quot;submit&quot;>


	</form>
	</BODY>
	</HTML>

NOW, the action:
Code:
<%@ LANGUAGE=&quot;VBSCRIPT&quot; %>
	<HTML>
	<HEAD>
	<TITLE>Upload File Results</TITLE>
	</HEAD>
	<BODY>

	<% Set upl = Server.CreateObject(&quot;SoftArtisans.FileUp&quot;) %>
	<%

	if upl.isEmpty = 1 then
	   Response.write(&quot;nothing to upload&quot;)
	   strFilename=&quot;&quot;
    else
	
	upl.path = &quot;e:\mydir&quot; 
    upl.form(&quot;f1&quot;).Save 
	  	 
	  strFilename=upl.form(&quot;f1&quot;)
'Get original name of file to store in database
	  set fs=Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
      strNominationFile=fs.getfilename(strfilename)
      response.write(&quot;filename = &quot; & strNominationFile & &quot;<br>&quot;) 
      set fs=nothing
%><BR>
	Total Bytes Written: <%=upl.TotalBytes%>
	<%end if
%>	</BODY>
	</HTML>

If I remove the check for isEmpty, the file is uploaded to my directory o.k. When I leave it in, it appears to upload, gives number of bytes, and no error message, but the file is not in the directory. I've searched asp.net and softartisans knowledge base to no avail.

Any ideas? Thanks in advance.
 
Well this is a snippet of the code that I use if it is of any use to you (and I haven't had any problems)

<%
Set upl = Server.CreateObject(&quot;SoftArtisans.FileUp&quot;)
'upl.Path = Server.MapPath (&quot;/uploads/filez&quot;)
upl.Path = Server.MapPath (&quot;/uploads/&quot;)
upl.MaxBytes = 5024000


If upl.IsEmpty Then
' Error - The Upload field was left blank
IsError = True
ErrorMessage = &quot;The filename you used is invalid. <b>Please try again.</b>&quot;

ElseIf upl.ContentDisposition <> &quot;form-data&quot; Then
' Error - Incompatibility with browser
IsError = True
ErrorMessage = &quot;Your upload was unsuccessful, probably due to an incompatibilty with your browser.</b>&quot;

Else
' on Error Resume Next
SavedFileName = Mid(upl.UserFilename, InstrRev(upl.UserFilename, &quot;\&quot;)+1)
SavedFileExtension = Mid(upl.UserFilename, InstrRev(upl.UserFilename, &quot;.&quot;))
If NOT GoodFileEx(SavedFileExtension) Then
' Error - File is not of type
IsError = True
ErrorMessage = &quot;The file you attempted to transmit is not of the acceptable download types. <b>Please convert your file to one of these file types and re-upload your file.</b>&quot;


Else
If upl.TotalBytes >= upl.MaxBytes Then
' Error - File is larger than MaxBytes property
IsError = True
ErrorMessage = &quot;The file you attempted to transmit is larger than our maximum allowable file size. <b>Please reduce the size of your file and re-upload your file.</b>&quot;


Else
upl.SaveAs SavedFileName
If Err <> 0 Then
' Error - Permissions problem on server
IsError = True
ErrorMessage = &quot;The file transmitted successfully however there was an error saving the file to the server. This is likely due to an incorrect filename specified or incorrect file permissions on the server.</b>&quot;


Else
IsError = False
Set rsDocument = Server.CreateObject(&quot;ADODB.Recordset&quot;)

'SQL = &quot;Insert INTO....&quot; ' insert the file extensions into the database for later retreival

End If
End If
End If
End If


%>
<%If IsError Then%>
<font face=&quot;Arial&quot; size=&quot;3&quot;><b>Upload Error!</b></font><br>
<font face=&quot;Arial&quot; size=&quot;2&quot;><%=ErrorMessage%></font>
<%Else%>
<font face=&quot;Arial&quot; size=&quot;3&quot;><b>Congratulations.</b></font><br>
<font face=&quot;Arial&quot; size=&quot;2&quot;>Your file transmitted and saved successfully.  The following is information about the file you just uploaded:</font>
<ul>
<li><font face=&quot;Arial&quot; size=&quot;2&quot;>Original File Name: <%=upl.UserFilename%></font></li>
<li><font face=&quot;Arial&quot; size=&quot;2&quot;>File Size: <%=upl.TotalBytes%></font></li>
<li><font face=&quot;Arial&quot; size=&quot;2&quot;>File Type: <%=upl.ContentType%></font></li>
</ul>

<%


'functions:

Function GoodFileEx(fileEx)

Select case fileEx
case &quot;.doc&quot;
bGood=True
case &quot;.zip&quot;
bGood=True
case &quot;.txt&quot;
bGood=True
case &quot;.ppt&quot;
bGood=True
case &quot;.pdf&quot;
bGood=True
case &quot;.xls&quot;
bGood=True
case else

bGood=False

End Select
GoodFileEx=bGood
End Function

%>
 
Thanks for your reply. I've been playing around with your script and it works great, but I have one question. On my form, I do error checking of other form elements. I need to do this before I upload any files to my server. So I do Set upl = Server.CreateObject(&quot;SoftArtisans.FileUp&quot;) and then retrieve other form elements. The user must enter a filename or some free text at one point. If the form is o.k., I upload the file. It reports that the file uploads fine, but the file is not on the server.

If I put the fileupload script at the beginning of the form action, the file is uploaded o.k., but I haven't checked form elements yet, so I'd have to delete the file if the user didn't enter all the required fields.

It seems that the moment other form elements are accessed, the file is unavailable. Any ideas?

I hope this makes sense, and thank you!
 
Yes that does make sense.

Can you do your form bit first and then validate it, before going on to let them upload their files? This is how I do it - you could use sub routines or different scripts to do the seperate parts.

If you do have to keep them together, then you are going to have to upload the file on the first pass, and then if they haven't filled in all form fields, you'll have to hash it so that the upload option disappears (you already have the file) and then just validate the form.

Have you looked on SoftArtisans website for documentation? The latest is at:

 
So what I'm seeing is how it really works...I'm not necessarily dong anything wrong?!!

I've looks at the documenttation already, but I guess I'll view it again and let you know how it works.

I have another script to write where they want to upload four files!

Thanks!
 
Are you using the upl.form(&quot;fieldname&quot;) or are you using request.form(&quot;fieldname&quot;) to retrieve your field values? I think you have to use the upl.form when using FileUp.

Other than that, I don't know the answer - unless you want to post your code here and there maybe something missing that could make it work?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top