Vad använder du för komponent för att ladda upp bilder till att börja med? Jag tror att de kommersiella som finns redan har inbyggt stöd för det, jag använder det på Loopia tex och dom kör ASPUpload och ASPJpeg, som funkar bra!
Ok, med ASPJpeg så har du ju tillgång till både width och height. Om ditt jpeg-objekt heter MyJpeg kan du kolla MyJpeg.Width och MyJpeg.Height. Det står ganska tydligt i ASPJpegs utmärkta online-manual. Vill du begränsa får du alltså i koden någonstans göra en if-sats som jämför. Du kan också automatiskt skala om bilder som är i fel storlek, om du vill det.
Jo, jag vet det men problemet är att jag har aldrig använr ASPJpeg. Det är första gången jag ska göra det. Och vet inte hur de ska vara. Skulle du kunna visa vilken manual det är du menar?
Det ät så att man ska kunna ladda upp ikoner till sin klubb som man har skapat på min sida.
Det behöver du väl inte alls, du behöver bara ha sökvägen till filen, enda skälet till att de väljer art använda aspupload som komponent är ju för att det är samma tillverkare.
Det behöver du väl inte alls, du behöver bara ha sökvägen till filen, enda skälet till att de väljer art använda aspupload som komponent är ju för att det är samma tillverkare.
<%
' Create an instance of AspUpload object
Set Upload = Server.CreateObject("Persits.Upload")
' Compute path to save uploaded files to
Path = Server.MapPath(".")
' Capture uploaded file. Return the number of files uploaded
Count = Upload.Save(Path)
If Count = 0 Then
Response.Write "No images selected."
Response.End
Else
' Obtain File object representing uploaded file
Set File = Upload.Files(1)
' Is this a valid image file?
If File.ImageType <> "UNKNOWN" Then
' Create instance of AspJpeg object
Set jpeg = Server.CreateObject("Persits.Jpeg")
' Open uploaded file
jpeg.Open( File.Path )
' Resize image according to "scale" option.
' We cannot use Request.Form, so we use Upload.Form instead.
jpeg.Width = jpeg.OriginalWidth * Upload.Form("scale") / 100
jpeg.Height = jpeg.OriginalHeight * Upload.Form("scale") / 100
SavePath = Path & "\small_" & File.ExtractFileName
' AspJpeg always generates thumbnails in JPEG format.
' If the original file was not a JPEG, append .JPG ext.
If UCase(Right(SavePath, 3)) <> "JPG" Then
SavePath = SavePath & ".jpg"
End If
jpeg.Save SavePath
' Save both images in the database along with description.
strConnect = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("../db/aspjpeg.mdb")
Set rs = Server.CreateObject("adodb.recordset")
rs.Open "images", strConnect, 1, 3
rs.AddNew
' Use File.Binary to access binary data of uploaded file.
rs("original_image").Value = File.Binary
Set ThumbFile = Upload.OpenFile(SavePath)
rs("thumbnail").Value = ThumbFile.Binary
rs("description") = Upload.Form("Description")
rs.Update
rs.Close
Set rs = Nothing
Response.Write "Success!"
Else
Response.Write "This is not a valid image."
Response.End
End If
End If
%>
Dock så får du modifiera uppladdningskomponenten så den passar dig.
<!-- #include file="_Inc/Conn.asp" -->
<body bgcolor="#FF99FF">
<form name="frmUpload" method="post" enctype="multipart/form-data" action="?Upload=groupIcon">
<div>
<input type="file" name="groupIcon" style="border-style:solid; border-width:1px; width: 480; font-family:Trebuchet MS; font-size:11px">
</div>
<div>
<input type="submit" value="Ladda upp" style="border-style:solid; border-width:1px; width: 99; font-family:Trebuchet MS; font-size:11px" name="LaddaUpp">
</div>
</form><%
IF Request.Querystring("Upload")="groupIcon" then
' Create an instance of AspUpload object
Set Upload = server.CreateObject("Dundas.Upload.2")
' Compute path to save uploaded files to
Path = Upload.save server.mappath("Icons\")
' Capture uploaded file. Return the number of files uploaded
Count = Upload.Files(1)
If Count = 0 Then
Response.Write "No images selected."
Response.End
Else
' Obtain File object representing uploaded file
Set Filename = Upload.Form("groupIcon")
' Is this a valid image file?
If Filename.ImageType <> "UNKNOWN" Then
' Create instance of AspJpeg object
Set jpeg = Server.CreateObject("Persits.Jpeg")
Response.Write File.Path
Response.End
' Open uploaded file
jpeg.Open( File.Path )
' Resize image according to "scale" option.
' We cannot use Request.Form, so we use Upload.Form instead.
jpeg.Width = jpeg.OriginalWidth * Upload.Form("groupIcon") / 60
jpeg.Height = jpeg.OriginalHeight * Upload.Form("groupIcon") / 10
SavePath = Path & "\small_" & File.ExtractFileName
' AspJpeg always generates thumbnails in JPEG format.
' If the original file was not a JPEG, append .JPG ext.
If UCase(Right(SavePath, 3)) <> "JPG" Then
SavePath = SavePath & ".jpg"
End If
jpeg.Save SavePath
' Use File.Binary to access binary data of uploaded file.
ObjConn.Execute("Update TLUsers set UsrPic='" &SavePath& "' where UsrID ="&SafeSQL(Session("UsrID"))&"")
ObjConn.Close : Set ObjConn = Nothing
Response.Write "Success!"
Else
Response.Write "This is not a valid image."
Response.End
End If
End If
End If
%>
Nu får jag detta felet:
DSUpload.CollFiles.2 error '80070057'
Index is out of range.
/upload.asp, line 21
De hära är rad 21
' Capture uploaded file. Return the number of files uploaded
Count = Upload.Files(1)
<!-- #include file="_Inc/Conn.asp" -->
<body bgcolor="#FF99FF">
<form name="frmUpload" method="post" enctype="multipart/form-data" action="?Upload=groupIcon">
<div>
<input type="file" name="groupIcon" style="border-style:solid; border-width:1px; width: 480; font-family:Trebuchet MS; font-size:11px">
</div>
<div>
<input type="submit" value="Ladda upp" style="border-style:solid; border-width:1px; width: 99; font-family:Trebuchet MS; font-size:11px" name="LaddaUpp">
</div>
</form><%
IF Request.Querystring("Upload")="groupIcon" then
' Create an instance of AspUpload object
Set Upload = server.CreateObject("Dundas.Upload.2")
' Compute path to save uploaded files to
Path = Upload.save(server.mappath("Icons\"))
' Capture uploaded file. Return the number of files uploaded
Count = Upload.Files(1)
If Count = 0 Then
Response.Write "No images selected."
Response.End
Else
' Obtain File object representing uploaded file
Set Filename = Upload.Form("groupIcon")
' Is this a valid image file?
If Filename.ImageType <> "UNKNOWN" Then
' Create instance of AspJpeg object
Set jpeg = Server.CreateObject("Persits.Jpeg")
Response.Write File.Path
Response.End
' Open uploaded file
jpeg.Open( File.Path )
' Resize image according to "scale" option.
' We cannot use Request.Form, so we use Upload.Form instead.
jpeg.Width = jpeg.OriginalWidth * Upload.Form("groupIcon") / 60
jpeg.Height = jpeg.OriginalHeight * Upload.Form("groupIcon") / 10
SavePath = Path & "\small_" & File.ExtractFileName
' AspJpeg always generates thumbnails in JPEG format.
' If the original file was not a JPEG, append .JPG ext.
If UCase(Right(SavePath, 3)) <> "JPG" Then
SavePath = SavePath & ".jpg"
End If
jpeg.Save SavePath
' Use File.Binary to access binary data of uploaded file.
ObjConn.Execute("Update TLUsers set UsrPic='" &SavePath& "' where UsrID ="&SafeSQL(Session("UsrID"))&"")
ObjConn.Close : Set ObjConn = Nothing
Response.Write "Success!"
Else
Response.Write "This is not a valid image."
Response.End
End If
End If
End If
%>