Welcome Guest!

If you do not have an account yet on The Web Squeeze forums, please Register! It’s FREE and there are many benefits:

  • Receive Fast Advice
  • Learn Programming Languages
  • Get Professional Website Reviews
  • Quick Troubleshooting Assistance

> Again Another Asp Problem (upload)

This is a discussion on Again Another Asp Problem (upload), within the ASP/.NET section. This forum and the thread "Again Another Asp Problem (upload)" are both part of the Programming Your Website category.

 
Reply to this topicStart new topic
> Again Another Asp Problem (upload)
crackafaza
post Jun 23 2008, 05:10 AM
Post #1


Squeezing
***

Group: Members
Posts: 62
Joined: 13-March 08
Member No.: 200



Hi,

I can't get an upload function to work on this website, and as I stated before, I don't know a thing about ASP, so was hoping you people could help me out. Here is the error I am receiveing:

An error occurred saving the image file to disk: Invalid procedure call or argument

Please find below the code I have, so if anyone could help I would be massively grateful:

CODE
<% @ Language = VBScript %>
<%
'Option Explicit

With Response
.Buffer = True
.Expires = 0
.Clear
End With


Function DeleteImages()
on error resume next
if strOldImageName <> "no_picture.gif" then
if strOldImageName <> "awaitingPic.jpg" then
  if strOldThumb <> "no_pictureSM.gif" then
   if strOldThumb <> "awaitingPicSM.jpg" then
    if strOldImageName <> oFile.FileName then
     'if they are not the same name as the other 2 images, which if we delete, will stop the other ones from being shown
     if strOldImageName <> otherPic2 then
      if strOldImageName <> otherPic3 then
       if strOldThumb <> otherThumb2 then
        if strOldThumb <> otherThumb3 then

' James code from here which will delete the image file b4 the recordset entry.
Dim File
Set File = CreateObject("Scripting.FileSystemObject")
      Dim ImagePath
   ImagePath = Server.MapPath("/user_images")
      ImagePath = ImagePath & "\" & strOldImageName
      
    if   File.FileExists(ImagePath) = true then
    
     File.DeleteFile(ImagePath)
    
    end if
    
Set File = nothing
  
   Set File2 = CreateObject("Scripting.FileSystemObject")
      Dim ImagePath2
   ImagePath2 = Server.MapPath("/user_images")
      ImagePath2 = ImagePath2 & "\" & strOldThumb
      File2.DeleteFile(ImagePath2)
    
    if   File2.DeleteFile(ImagePath2) = true then
    
     File2.DeleteFile(ImagePath2)
    
    end if
Set File2 = nothing
        
        end if
       end if
      end if
     end if
    end if
   end if
  end if
end if
end if

end function

strPicNum = request.QueryString("Picture")

If strPicNum = "1" then
strPic = "Pic1"
strThumb = "Thumb1"
otherPic2 = "Pic2"
otherThumb2 = "Thumb2"
otherPic3 = "Pic3"
otherThumb3 = "Thumb3"
End if
If strPicNum = "2" then
strPic = "Pic2"
strThumb = "Thumb2"
otherPic2 = "Pic1"
otherThumb2 = "Thumb1"
otherPic3 = "Pic3"
otherThumb3 = "Thumb3"
End if
If strPicNum = "3" then
strPic = "Pic3"
strThumb = "Thumb3"
otherPic2 = "Pic1"
otherThumb2 = "Thumb1"
otherPic3 = "Pic2"
otherThumb3 = "Thumb2"
End if

strUserID = Request.cookies("AuthCode")("UserID")
strUserName = Request.cookies("AuthCode")("UserName")
%>

<!-- #INCLUDE FILE = "obj_FileUpload_beta_full.asp" -->
<!-- #include virtual="/Connections/connSQLServer.asp" -->
<html>
<head>
<title>Date42.com - The Internet's Number One Singles & Dating Site! </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!-- body {  font-family: MS Sans Serif; font-size: 14px; font-style: normal; font-weight: bolder; color: #FF0000}
-->
</style>
</head>

<body bgcolor="#FFFFFF" text="#000000">

<%
'declare some variables to facilitate working with the objects comprising fileupload.
Dim oFO, oProps, oFile, i, item, oMyName

'create an instance of FileUpload. FileUpload is the only object that you will
'directly set an instance of. The other classes are returned by various methods
'of the object.
Set oFO = New FileUpload

'print version
' By James - Response.Write("<H3>FileUpload Object v" & oFO.Version & "</H3>")

'call the GetUploadSettings method to return an instance of the FO_Properties
'object for this instance of FileUpload. FO_Properties contains all the
'property settings for uploads.
Set oProps = oFO.GetUploadSettings
with oProps

  'the FO_Properties object contains 6 properties. Each property has a default
  'so you only need to set the properties if the defaults do not meet
  'your intended usage scheme.

  'allowable file extensions
.Extensions = Array("gif", "jpg")

  'upload directory
.UploadDirectory = Server.Mappath("/temp_images/")

  'file overwrite option
.AllowOverWrite = true

  'max file size for EACH file to upload (older versions of the class
  'only check the entire post stream's length once at the beginning)
.MaximumFileSize = 200000  ' give or take 50k for each file

  'minimum file size for each file to upload (older versions of the class
  'only check the entire post stream's length once at the beginning)
.MininumFileSize = 1000 ' 1k

  'disable uploading
.UploadDisabled = false
End with

'all the properties you set above are remembered by the FileUpload class as soon
'as they are set so there's no reason not to destroy the FO_Properties object we
'just used to modify the upload system properties to save memory.
set oProps = nothing

'default method. Processupload must be called to set everything up. After
'ProcessUpload is called, the remaining properties, methods and objects
'exposed by fileupload become available and are populated with data.
oFO.ProcessUpload

'the totalformcount property returns the total count of everything submitted
'to the fileupload object. this includes binary input from files and text form
'inputs posted from a form.
if oFO.TotalFormCount > 0 then

  'the filecount property returns the count of all binary form inputs that
  'were read and loaded by the class after ProcessUpload was called. It is
  'not an accurate count of acceptable files, it merely counts the number
  'of binary form inputs parsed.
if oFO.FileCount > 0 then

   'you can easily use the FileCount property to setup a loop to
   'go through all files that are attempting to be uploaded.
  for i = 1 to oFO.FileCount

    'the fileupload's file object returns a FO_File object
    'containing properties and methods that allow you to
    'view components of the file and perform actions on
    'the file. The File method's argument expects a long
    'integer in the range of 1 to FileCount.
   set oFile = oFO.File(i)
   ' By James - response.write "<HR><B>file #" & i & "</B><HR>"

    'if an error has occurred when the FO_File object was
    'being created or filled with data, it will be in the
    'ErrorMessage property of the returned FO_File object.
   if oFile.ErrorMessage <> "" then
    response.write "An error occurred while attempting to upload your image file: <br><br>" & _
     oFile.ErrorMessage & "<BR>"
   else

    'rename file
    'oFile.FileName = "newfile.txt" & "." & oFile.FileExtension

     'there are a couple of different options for
     'saving files. in this case, i want a copy
     'of the uploaded file on the server so I use
     'the saveasfile method.
    oFile.SaveAsFile

     'after saving an uploaded file using any of the
     'various save methods available, you should check
     'the upload successful property to ensure that
     'the file was saved properly. In the event of an
     'error during I/O, UploadSuccessful always returns
     'false.
    if oFile.UploadSuccessful then
     response.write ("<BR><br><div align=""center"">File uploaded successfully</div><BR><br><BR><br>")

      'contenttype - returns the content-type of the
      'uploaded file.
     ' By James - response.write(" - content-type: " & oFile.ContentType & "<BR>")

      'filename - returns the filename of the uploaded
      'file, including extension.
     'response.write(" - file name: " & oFile.FileName & "<BR>")
     response.write ("<div align=""center""><img src=../../../temp_images/" & oFile.FileName & " width=150></div><BR>")
    
  
    
      'bytecount - returns the binary length of the saved file.
      'this accurately represents the size of the file in bytes
      'on the server.
     'response.write(" - file size: " &      formatnumber(oFile.ByteCount, 0) & " bytes<BR>")

'james code from here

'*******************************************************************

'Open connection to user table and write online
Dim conn
set conn = Server.CreateObject("ADODB.connection")
conn.open MM_connSQLServer_STRING

' first get the Original Pic1 so we can delete it off the server
Dim rsGetNameToDelete
set rsGetNameToDelete = conn.execute("SELECT " & strPic & ", " & strThumb & ", " & otherPic2 & ", " & otherThumb2 & ", " & otherPic3 & ", " & otherThumb3 & " FROM date42.tblUser WHERE UserID = '" & strUserID & "'")



Dim strOldImageName
WHILE NOT rsGetNameToDelete.EOF
  strOldImageName = Rtrim(rsGetNameToDelete(""&strPic&""))
  strOldThumb = RTrim(rsGetNameToDelete(""&strThumb&""))
  
  otherPic2 = Rtrim(rsGetNameToDelete(""& otherPic2 &""))
  otherThumb2 = Rtrim(rsGetNameToDelete(""& otherThumb2 &""))
  otherPic3 = Rtrim(rsGetNameToDelete(""& otherPic3 &""))
  otherThumb3 = Rtrim(rsGetNameToDelete(""& otherThumb3 &""))

  rsGetNameToDelete.movenext()
WEND


Call DeleteImages


Dim rsPicture

strAwaitPic = "awaitingPic.jpg"
strAwaitThumb = "awaitingPicSM.jpg"

set rsPicture = conn.execute("UPDATE date42.tblUser SET " & strPic & " = '" & strAwaitPic & "', " & strThumb & " = '" & strAwaitThumb & "'  WHERE UserID = '" & strUserID & "'")




strNewImageUploadName = Replace(oFile.FileName,"'","''")
strNewImageUploadName = Replace(strNewImageUploadName,"""","""")

set rsNewPicture = conn.execute("INSERT INTO date42.tblNewImages(UserID, UserName, " & strPic & ") VALUES('" & strUserID & "', '" & strUserName & "', '" & oFile.FileName & "')")

'end if
'*******************************************************************
'****************************************************************************
**
'****************************************************************************
**
'email admin here
'email the new user
Dim Emfrom
Dim Emsub
Dim Emto
Dim Emcc
Dim Embcc
Dim Embody
Dim Emattach

Emfrom = "[email="photos@date42.com"]photos@date42.com[/email]"
Emsub = "New Picture"
Emto = "[email="photos@date42.com"]photos@date42.com[/email]"
Emcc = ""
Embcc = ""
Embody = "New Picture to be put online." & vbcrlf & vbcrlf & "ImageName:-" & strNewImageUploadName & vbcrlf & vbcrlf & "--------------------" & vbcrlf
Emattach = ""

'Dim ObjCdo
  Dim objMail
  Set objMail = CreateObject("CDO.Message")
  Dim iConf
  Set iConf = CreateObject("CDO.Configuration")
  Dim Flds
  Set Flds = iConf.Fields
  Flds("[url="http://schemas.microsoft.com/cdo/configuration/sendusing"]http://schemas.microsoft.com/cdo/configuration/sendusing[/url]") = 1
  Flds( _
  "[url="http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory"]http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory[/url]") _
  = "c:\inetpub\mailroot\pickup"
  Flds.Update
ObjMail.From = Emfrom
ObjMail.Subject = Emsub
ObjMail.To = Emto
ObjMail.cc = Emcc
ObjMail.bcc = Embcc
ObjMail.Htmlbody = Embody
'ObjCDO.AttachFile(Emattach)

ObjMail.send

Set ObjMail = nothing
%>

<script language="JavaScript">
<!--
function MM_callJS(jsStr) { //v2.0
  opener.document.location = "../../my_pictures.asp"
  return eval(jsStr)
  
}
//-->
</script>


<%

response.write "<BR><BR><div align=""center"">Your image will be verified and will appear online within 24 hours.</div><br><br><div align=""center""><A HREF=" & Chr(34) & "#"  & Chr(34) & "onClick=" & Chr(34) & "MM_callJS('window.close()')" & Chr(34) & ">Click here to close this window</A></div>"

    else
     response.write "An error occurred saving the image file to disk: " & _
      oFile.ErrorMessage & "<BR>"
    end if
   end if

    'release file object to save memory.
   set oFile = Nothing

   'retrieve next file object (if any)
  next
else

   'if a form doesn't have any binary inputs on it, the filecount
   'property will return 0 (no <input type=file> inputs)
  response.write "&gt; no binary file content submitted."
end if
  
'taken from here*****************88888

else

  'if the totalformcount property returns 0, no input was posted to the page
  'so we might as well show the upload form and give them a chance to upload.
oFO.ShowUploadForm request.servervariables("SCRIPT_NAME")
end if

'release FileUpload object to save memory.
set oFO = Nothing
%></body>
</html>


Thanks
Craig biggrin.gif
Go to the top of the page
 
+Quote Post
Monie
post Aug 11 2008, 04:54 AM
Post #2


ASP Advisor
*****

Group: Advisors
Posts: 655
Joined: 13-February 08
From: Borneo
Member No.: 8



I am sorry if this is a cheat reply to your post but what the heck! At least I have the intention to help, right?
Here is what i found from google: link


--------------------
Monieweb.com - So much to learn, so little time!

QUOTE
The brain is a wonderful organ. It starts working the moment you get up in the morning, and does not stop until you get into the office!

Go to the top of the page
 
+Quote Post
Monie
post Aug 21 2008, 12:28 AM
Post #3


ASP Advisor
*****

Group: Advisors
Posts: 655
Joined: 13-February 08
From: Borneo
Member No.: 8



hai Craig!
Did you manage to solve the above problem? biggrin.gif


--------------------
Monieweb.com - So much to learn, so little time!

QUOTE
The brain is a wonderful organ. It starts working the moment you get up in the morning, and does not stop until you get into the office!

Go to the top of the page
 
+Quote Post
If you found The Web Squeeze to be helpful, please donate so we can keep this site FREE, FRESH, and fortified with Web Design & Development info!
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts   11 unitedcraig 238 20th February 2008 - 02:48 AM
Last post by: Monie
No New Posts   3 mcdanielnc89 151 23rd February 2008 - 08:14 AM
Last post by: Marc
No New Posts   6 karinne 192 20th February 2008 - 06:52 PM
Last post by: Stuart
No New Posts 0 karinne 157 22nd February 2008 - 07:55 AM
Last post by: karinne
No New Posts 0 karinne 240 22nd February 2008 - 07:58 AM
Last post by: karinne