If I paste part of the code to my script could someone help me out if it is a simple fix?
Thanks! Code below:
line 25 would be: File.SaveAs Path & "" & Answer
[CODE]Set Upload = Server.CreateObject(“Persits.Upload”)
'On Error Resume Next
’ we use memory uploads, so we must limit file size
Upload.SetMaxSize 1048576, True ’ Limit files to 1MB
’ Save to memory. Path parameter is omitted
Upload.Save
txtID = Upload.Form(“homeID”)
txtPicture = Upload.Form(“txtPicture”)
txtPicNum = Upload.Form(“txtPictureNum”)
txtProp = Upload.Form(“txtProperty”)
Upload.OverwriteFiles = True
’ Save files to it. Our form has only one file item
’ but this code is generic.
For Each File in Upload.Files
Answer = txtPicNum & “_” & txtID & RIGHT(File.FileName, 4)
File.SaveAs Path & "" & Answer
’ Database Open[/CODE]
Upload.OverwriteFiles = True
’ Save files to it. Our form has only one file item
’ but this code is generic.
For Each File in Upload.Files
Answer = txtPicNum & “_” & txtID & RIGHT(File.FileName, 4)
’ File.SaveAs Path & "" & Answer
File.SaveAs Path & “/” & Answer
’ Database Open
Sorry for that. U’ll have to use virtual. Below code is tested and works. Plz try and let me know.
U will have to create a subdirectory “upload” under the folder where u run this script.
Cheers
Yogesh
<%
Set Upload = Server.CreateObject(“Persits.Upload”)
Upload.OverwriteFiles = False
’ On Error Resume Next
’ we use memory uploads, so we must limit file size
Upload.SetMaxSize 100000, True
’ Save to memory. Path parameter is omitted
Upload.Save
Set File = Upload.Files(“FILE1”)
If Not File Is Nothing Then
’ Obtain file name
Filename = file.Filename
’ check if file exists in c:\upload under this name
If Upload.FileExists(“upload/” & filename ) Then
Response.Write “File with this name already exists.”
Else
’ otherwise save file
File.SaveAsVirtual “upload/” & File.Filename
Response.Write "File saved as " & File.Path
End If
Else ’ file not selected
Response.Write “File not selected.”
End If
%>
Sorry for so many questions, but here is my original code, do I omit what you didn’t include in your example or ?
Thanks for the help!!!
[CODE]<%@ LANGUAGE=VBSCRIPT %>
<%response.buffer = TRUE%>
<%
Set Upload = Server.CreateObject(“Persits.Upload”)
'On Error Resume Next
’ we use memory uploads, so we must limit file size
Upload.SetMaxSize 1048576, True ’ Limit files to 1MB
’ Save to memory. Path parameter is omitted
Upload.Save
txtID = Upload.Form(“homeID”)
txtPicture = Upload.Form(“txtPicture”)
txtPicNum = Upload.Form(“txtPictureNum”)
txtProp = Upload.Form(“txtProperty”)
Upload.OverwriteFiles = True
’ Save files to it. Our form has only one file item
’ but this code is generic.
For Each File in Upload.Files
Answer = txtPicNum & “_” & txtID & RIGHT(File.FileName, 4)
'File.SaveAs Path & "" & Answer
File.SaveAs Path & “/” & Answer
'Database Open
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open "Driver={MySQL ODBC 3.51 Driver}; Server=mysql1.g********.com; Database=alcadmi_main; UID=admin; PWD=******; Option=3"
sSQL = "UPDATE rent_homes " & _
"SET Picture" & txtPicNum &" = '" & Answer & "' WHERE homeID=" & txtID & ";"
oConn.Execute sSQL
If Err.Number = 0 Then
Session("strErrorID_result") = "Success: "
Session("strErrorDescription_result") = UCASE(Answer) & " was updated."
oConn.Close
Set oConn = Nothing
Response.Redirect("property_edit.asp?homeID=" & txtID)
Else
Session("strErrorID_result") = Err.Number
Session("strErrorDescription_result") = Err.Description
oConn.Close
Set oConn = Nothing
Response.Redirect("property_edit.asp?homeID=" & txtID)
End If
Next
I am ok to answer the questions as far as I understand them, so plz feel free to post your Qs untill it gets resolved.
Ok here is the exact snippet where you need to change (* plz note the SaveAsVirtual) -
Existing -
For Each File in Upload.Files
Answer = txtPicNum & “_” & txtID & RIGHT(File.FileName, 4)
'File.SaveAs Path & "" & Answer
File.SaveAs Path & “/” & Answer
'Database Open
Change To
For Each File in Upload.Files
Answer = txtPicNum & “_” & txtID & RIGHT(File.FileName, 4)
File.SaveAsVirtual Path & “/” & Answer
'Database Open
Now I get:
Save method must not be called more than once.
/admin/PIC_Upload.asp, line 22
Line 22 is:
Upload.Save
Just our of curiosity I tried removing that line and the script appears to work without errors but the file was not actually uploaded.
You had asked that I create a folder upload under the directory of the script but I was already using a folder properties that referenced in the path statement.
So I changed: If Upload.FileExists(“upload/” & filename ) Then
and File.SaveAsVirtual “upload/” & File.Filename
to If Upload.FileExists(“properties/” & filename ) Then
and File.SaveAsVirtual “properties/” & File.Filename
That seems to work and I can upload photos now.
But, if I go back to edit or change and existing photo the photo will not change and I see filenames like:
1_57.jpg
1_57(2).jpg
1_57(3).jpg
But maybe it had that problem before I moved to this server, not sure, I just took over the website.
Good to know that the upload is working now.
BTW while exchanging messages I put the following line in the code -
Upload.OverwriteFiles = False
Which earlier was
Upload.OverwriteFiles = True
So whenever there is existing file with same name as file being uploaded then the new file will be created with some extension.
So you are getting it -
1_57.jpg
1_57(2).jpg
1_57(3).jpg
You may turn this feature ON/OFF by setting True or False depending on your requirement. But better to keep it False as there is always a chance that users will use very generic names for their images. like house.jpg, James.jpg etc. So one user can overwrite the other users pic.
Wish u good luck in your project.
I am into SEM and SEO. If have any requirements for your site or your client’s site plz IM me.