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

Uploading images with an ASP script

Status
Not open for further replies.

Kris912

Programmer
Joined
Jul 29, 2005
Messages
27
Location
US
Hi,
I am using an asp script to upload images and I am using the ID as the image name. I am using the same code on another site and it functions fine...I am stuck with this one. Here it is...

Set Upload = Server.CreateObject("Persits.Upload")
Upload.Save ("C:\Temp")
Set File = Upload.Files("MyFile")

ID = Upload.form("ID")
Title = replace(trim(Upload.form("Title")),"'","''")
EventDate = Upload.form("EventDate")
Description = replace(trim(Upload.form("Description")),"'","''")
Notes = replace(trim(Upload.form("Notes")),"'","''")


set connection = server.createobject("ADODB.Connection")
connection.open session("DBConnString")

sql = "select ID from Events where Title='" & Title & "'"
set rs = connection.execute(sql)

(Does it make sense to query it this way?)

(If I wanted to write it based only on the ID would it be written as: sql = "select ID from Events where ID= " & ID)


if not rs.eof then
%>
<script language="JavaScript">
alert("The project '<% = Title %>' has already been entered, please try again!");
history.back();
</script>
<%
else
' Upload Images
If Not File Is Nothing Then
i = 0
for each File in Upload.Files
i = i + 1
If File.ImageType <> "UNKNOWN" Then
Set jpeg = Server.CreateObject("Persits.Jpeg")

if i = 1 then
jpeg.Open(File.Path)
jpeg.Width = 150
jpeg.Height = 115
SavePath = Server.Mappath("Photos\" & ID & "-Thumb.jpg")
jpeg.Sharpen 1,110
jpeg.Save SavePath

jpeg.Open(File.Path)
jpeg.Width = 300
jpeg.Height = 225
SavePath = Server.Mappath("Photos\" & ID & ".jpg")
jpeg.Sharpen 1,110
jpeg.Save SavePath
else
jpeg.Open(File.Path)
jpeg.Width = 300
jpeg.Height = 225
SavePath = Server.Mappath("Photos\" & ID & "-" & i & ".jpg")
jpeg.Sharpen 1,110
jpeg.Save SavePath
end if
else
%>
<script language="JavaScript">
alert("There is a problem with the image you uploaded, please try again.\n\nIf the problem persits, call Graphic Memory Internet Services at 757-850-3231.");
history.back();
</script>
<%
end if
next
else
'Response.Write "No images selected."
'Response.End
end if

' Update Database
sql = "insert into Events (Title,EventDate,Description,Notes) VALUES("
sql = sql & "'" & Title & "',"
sql = sql & "'" & EventDate & "',"
sql = sql & "'" & Description & "',"
sql = sql & "'" & Notes & "')"
set rs = connection.execute(sql)

set fso = server.createobject("Scripting.FileSystemObject")

' Check to see if image exists
if fso.FileExists(Server.Mappath("Photos\" & ID & ".jpg")) then
PhotoImage = "Photos\" & ID & ".jpg"
else
PhotoImage = "Photos\NoPhoto.jpg"
end if

set fso = nothing
end if

I've had a hard time figuring this one out because I don't get any error messages.

Thanks so much for your help!

Kris :)
 
else
PhotoImage = "Photos\NoPhoto.jpg"

instead of this can you put an alert in jscript to see if the images exist in the filepath?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top