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

Need to click twice before I can upload a file!

Status
Not open for further replies.

vias

Programmer
Apr 25, 2000
54
GB
I am using ASPSmartUpload to load photos.

The user has to click twice on the "submit" button
before the photo(image file) is uploaded. After the
first click ..it seems to be doing some thing but one
actually needs to click again before the file is uploaded.

Here is the process:
There is a default photo. So, when the user actually
uploads his photo, first I delete the default file
then I take the first part of the uploaded file name
and rename(movefile) it to his username with the file
extension unchanged.

Please find below the form and the ASP code.

Could anybody tell me why I need to click a second
time to upload a file.

Thanks.
-----------------form---------------------------------------
<FORM METHOD=&quot;POST&quot; ENCTYPE=&quot;multipart/form-data&quot; ACTION=&quot;snapSmart.asp&quot; id=pictureForm name=pictureForm onsubmit=&quot;return checkPictureForm();&quot;>

<table border=0 align=center><tr><td valign=middle><INPUT TYPE=FILE SIZE=60 NAME=&quot;file1&quot;></td></tr>
<tr><td align=center><INPUT TYPE=SUBMIT VALUE=&quot;submit&quot; id=SUBMIT1 name=SUBMIT1>
</td></tr></table>
</FORM>
------------------code-----------------------------------

dim upload, File, fileExt
dim UploadPath, Count
dim conn, rs, objFSO
Dim start_time, end_time, str_filename, lng_size

UploadPath = server.MapPath(&quot;.&quot;) & &quot;\common\&quot;

start_time = now()
Set Upload = Server.CreateObject(&quot;aspSmartUpload.SmartUpload&quot;)

Upload.Upload

For each file In Upload.Files

str_filename = file.filename
lng_size = file.Size
fileExt = Mid(str_filename, InStrRev(str_filename, &quot;.&quot;) + 1)

If not file.IsMissing Then

if fileExt=&quot;jpg&quot; or fileExt=&quot;gif&quot; then

if lng_size < 50000 then
file.SaveAs(UploadPath & file.FileName)

end_time = now()

Response.Write &quot;Your picture <b>&quot;& File.FileName &&quot;</b> has been uploaded successfully. <BR>&quot;


set objFSO = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)

objFSO.DeleteFile UploadPath & session(&quot;Uname&quot;)&&quot;.&quot;& fileExt

objFSO.movefile UploadPath & str_filename, UploadPath & session(&quot;Uname&quot;)&&quot;.&quot;& fileExt

set objFSO = nothing


set conn = Server.CreateObject(&quot;adodb.Connection&quot;)
conn.Open Application(&quot;strConn&quot;)
set rs = Server.CreateObject(&quot;adodb.Recordset&quot;)
rs.Open &quot;select * from QProfile where uname='&quot; & session(&quot;Uname&quot;) & &quot;'&quot;,conn,1,3
rs(&quot;Snap_FExt&quot;) = &quot;.&quot; & fileExt
rs.Update
rs.Close
set rs = nothing
conn.Close

Response.redirect &quot;Mypage.asp?uname=&quot;& session(&quot;Uname&quot;)

else
Response.Write &quot;Image size should be less then equal to 50KB. <BR>&quot;
end if
else
Response.Write &quot;Image format should be either JPG or GIF. <BR>&quot;
end if
end if
next
 
there may be a error in this function causing it
checkPictureForm()

sometimes a error in the client script will stop a initial run but then run through the second time as the function in a sense is thus disabled.

nothing is jumping out in the ASP coding side of things asying a reason for it

____________________________________________________
The most important part of your thread is the subject line.
Make it clear and about the topic so we can find it later for reference. Please!! faq333-3811

onpnt2.gif
 
if you havent gotten this resolved yet, if you could post the checkPictureForm() function we might be able to point it out for you.
 
Thanks for responding.
Here is the function:

---------------------------------------------------------

function checkPictureForm(){
var error = false;
if (document.pictureForm.file1.value == &quot;&quot;){
alert(&quot;Please select the picture to be added.&quot;);
document.pictureForm.file1.focus();
error = true;
}

if (error == false){
document.pictureForm.submit();
}
else
return false;
}
 
Hi all,

Can anybody help me in finding out
the part of the code in 'checkPictureForm'
causing the problem.

Thanks in advance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top