Click to See Complete Forum and Search --> : File uploading


wtpandar
08-09-2006, 01:47 AM
Hi,

I have borrowed an ASP script that performs file uploading. This all works if i want to just upload the file to a directory on the server.

However, I have several parameters that i wish the user to select when s/he uploads a file. The parameters that the user has selected will be used as the filename of the uploaded file.

My problem is i can't take any of these parameters until the file has been uploaded.

The files that i have work as follows

uploading form page (.html) --- calls ---> upload.asp

I have basically do a "request.Form.." call to get the values.

This is the code for my uploading form



<html>
<head>
<title>Upload to Image Bank</title>
<link rel="stylesheet" type="text/css" href="pop_style.css" />
<script>

var fileOK = new Array(2);
var uploadsOK = false;


extArray = new Array(".gif", ".jpg", ".png");

fileOK[0] = false;
fileOK[1] = false;



function LimitAttach(form, file, fileNum) {
allowSubmit = false;
if (!file) return;
while (file.indexOf("\\") != -1)
file = file.slice(file.indexOf("\\") + 1);
ext = file.slice(file.indexOf(".")).toLowerCase();
for (var i = 0; i < extArray.length; i++) {
if (extArray[i] == ext) { allowSubmit = true; break; }
}
if (allowSubmit) fileOK[fileNum] = true;
else {
fileOK[fileNum] = false;
}
}

function validate_form () {
return true;
}

</script>
</head>

<body>
<form name="upLoadForm" method="post" enctype="multipart/form-data" action="upload.asp" onsubmit="return validate_form()">
<center>
<span id="main_body" style="display: ';'">
<table cellpadding="10">
<tr>
<td colspan="2" class="largeHead" align="center" height="60">
Image bank uploader<hr size="2"></td>
</tr>
<tr>
<td class="smallHead">Centre:&nbsp;</td>
<td><select name="centre"><option value="x">X
<option value="y">Y
</select></td>
</tr>
<tr>
<td class="smallHead">Category:&nbsp;</td><td><select name="category">
<option value="1">A
<option value="2">B


</select></td>
</tr>
<tr>
<td class="smallHead">Image file 1:&nbsp;</td>
<td><input type="file" name="file1" onblur="LimitAttach(this.form, this.form.file1.value, 0);" size=40></td>
</tr>
<tr>
<td class="smallHead">Short description <br><font class="foot">
(max 100 characers)</font>:&nbsp;</td>
<td><input type="text" name="file1_desc" size="40" maxlength="100"></td>
</tr>
<tr>
<td class="smallHead">Image file 2:&nbsp;</td>
<td><input type="file" name="file2" onblur="LimitAttach(this.form, this.form.file2.value, 1);" size=40></td>
</tr>
<tr>
<td class="smallHead">Short description <br><font class="foot">
(max 100 characers)</font>:&nbsp;</td>
<td><input type="text" name="file2_desc" size="40" maxlength="100"></td>
</tr>
</table>

<p><input type="submit" value="Submit">
</span>
</center>
</form>
</body>
</html>



And this calls upload.asp



<%
Dim cat, location, desc(2), catArray

Dim uploadsDirVar, Upload, fileSize, ks, i, fileKey, FSO

cat = request.Form("category")
catArray = split(cat, ",")
location = request.Form("centre")
desc(0) = request.Form("file1_desc")
desc(1) = request.Form("file2_desc")

uploadsDirVar = "E:\Data\images"


'This calls the upload images function
SaveFiles()

function SaveFiles

Set Upload = New FreeASPUpload
Upload.Save(uploadsDirVar)


' If something fails inside the script, but the exception is handled
If Err.Number<>0 then Exit function

SaveFiles = ""
ks = Upload.UploadedFiles.keys

if (UBound(ks) <> -1) then
SaveFiles = "<B>Files uploaded:</B> "
for each fileKey in Upload.UploadedFiles.keys
SaveFiles = SaveFiles & Upload.UploadedFiles(fileKey).FileName & _
" (" & Upload.UploadedFiles(fileKey).Length & "B) "

next
else
SaveFiles = "The file name specified in the upload form does not " & _
" correspond to a valid file in the system."
end if

end function

'********************************* END Upload code *****************************%>



I am using a freeASPuploader from

http://www.freeaspupload.net

What am i doing wrong?

russell
08-09-2006, 09:39 AM
can't use request.form with a binary read (file upload). put the parameters on a different form/page, and get 'em either b4 or after the upload is easiest

ejrhodes
08-09-2006, 01:37 PM
I have not looked at the code of the uploadasp component but you should check and see if they are storing the "form variables" in an array of some sort after they load the files. AS the other guy said, once you set the form type to allow file uploads, you can not call the request object anymore. That said, there is logic out there to parse the header to get the variables and I imagine the code already does some of that.