Bertel Lund Hansen wrote:
> Kurt G. skrev:
>
>> Det er meget sjældent mig, der skal lave den upload,
>
> Nå sådan. Så ville jeg lave det med et PHP-script og leve med at
> det tager tid at uploade. Folk lærer nok efterhånden at
> nedskalere builleder der skal på nettet, og ellers må de finde
> sig i de ulemper det giver ikke at gøre det.
Hvis man savner en skaleringsfunktion, så er her en ASP funktion, der burde
være ligetil at PHP-ficere:
...................
<%@ LANGUAGE = VBScript%><%Option Explicit%><%
Dim pagetitle
pagetitle = "W.O.P.R Gallery - Gallery Add picture to gallery " +
Request.QueryString("GalleryName")
%><!--#include virtual="/include_files/doctype.inc.asp"-->
</head>
<body>
<!--#include virtual="/include_files/body.start.inc.asp"-->
<!--#include file="gallerydb.inc.asp"--><!--#include
virtual="/include_files/sql.inc.asp"-->
<%
Dim SQL
Dim Parameters(30)
Dim Rowsaffected
Dim rs
SQL = "SELECT GalleryOwner FROM GalleryOwners WHERE GalleryOwner = ? "
Parameters(0) = Session("Loginuser")
Set rs= Query(oConn,SQL,Parameters,1)
if rs.eof then
Response.Write "Not logged in"
Response.End
end if
rs.close
set rs = nothing
if Request.Servervariables("REQUEST_METHOD") = "GET" then
SQL = "SELECT GalleryName FROM Galleries WHERE GalleryOwner = ? AND
GalleryName = ?"
Parameters(0) = Session("Loginuser")
Parameters(1) = Request.QueryString("GalleryName")
Set rs= Query(oConn,SQL,Parameters,2)
if rs.eof then
Response.Write "No galleries in"
Response.End
end if
%>
<h3>Opret billede for bruger: <%=session("Loginuser")%></h3>
<form enctype="multipart/form-data" method="POST">
<div>
<label>Galleri: <%=rs("GalleryName")%><input type="hidden"
name="GalleryName" value="<%=rs("GalleryName")%>"/></label><br/>
<label>Billedefil<input type="file" name="picture"/></label><br/>
<label>Overskrift<input type="text" name="PictureHead"
value="overskrift"/></label><br/>
<label>Beskrivelse<textarea name="PictureText" cols="60"
rows="10"></textarea></label><br/>
<input type="submit" value="Opret"/>
</div>
</form>
</body></html>
<%
rs.close
set rs = nothing
Response.End
end if
Dim Upload
Set Upload = Server.CreateObject("Persits.Upload")
Upload.SetMaxSize 512000, True
Upload.Save ' Server.MapPath("uploadfiles")
SQL = "SELECT
GalleryOwner,GalleryName,NumberOfPictures,ThumbnailWidth,ThumbnailHeight,ThumbnailType,BigPictureWidth,BigPictureHeight
FROM Galleries WHERE GalleryName = ? AND GalleryOwner = ? "
Parameters(0) = Upload.Form("GalleryName")
Parameters(1) = Session("Loginuser")
Set rs= Query(oConn,SQL,Parameters,2)
if rs.eof then
Response.Write "Fejl ved galleri, ej fundet"
Response.End
end if
Response.Write "File: " + Upload.Files("picture").Name + " size: " +
cStr(Upload.Files("picture").Size) + " type: " +
Upload.Files("picture").ContentType
' her skal noget height ind
Dim fs
Dim path
Dim jpeg,gif
Dim picturenumber
Dim fileExt
Dim Thumbwidth,Thumbheight, PictureWidth,PictureHeight,PicturePath
fileExt = ".jpg"
Thumbwidth = rs("ThumbnailWidth") * 2
Thumbheight = rs("ThumbnailHeight") * 2
picturenumber = rs("NumberOfPictures") + 1
PicturePath = Upload.Files("picture").Path
path = Server.MapPath(replace(session("Loginuser")," ","_")+ "\" +
Upload.Form("GalleryName"))
Set Jpeg = Server.CreateObject("Persits.Jpeg")
Jpeg.OpenBinary Upload.Files("picture").Binary
if Upload.Files("picture").ContentType = "image/png" then
' Jpeg.PNGOutput = True
fileExt = ".png"
end if
if Upload.Files("picture").ContentType = "image/gif" then
fileExt = ".gif"
end if
if rs("BigPictureWidth") = 0 and rs("BigPictureHeight") = 0 or _
rs("BigPictureWidth") > 0 and rs("BigPictureHeight") = 0 and
jpeg.Width <= rs("BigPictureWidth") or _
rs("BigPictureWidth") > 0 and rs("BigPictureHeight") > 0 and
jpeg.Width <= rs("BigPictureWidth") and jpeg.Height <=
rs("BigPictureHeight") then
Upload.Files("picture").SaveAs Path + "\picture_" +
cstr(picturenumber) + fileExt
else
if rs("BigPictureWidth") > 0 and rs("BigPictureHeight") = 0 then
PictureHeight = jpeg.Height * rs("BigPictureWidth") \ jpeg.Width
PictureWidth = jpeg.Width
else
if rs("BigPictureWidth") > 0 and rs("BigPictureHeight") > 0 then
if jpeg.Width / jpeg.Height > rs("BigPictureWidth") /
rs("BigPictureHeight") then
PictureWidth = rs("BigPictureWidth")
PictureHeight = jpeg.Height * PictureWidth \ jpeg.Width
else
PictureHeight = rs("BigPictureHeight")
PictureWidth = (jpeg.Width * PictureHeight) \ jpeg.Height
end if
end if
end if
jpeg.Width = PictureWidth
jpeg.Height = PictureHeight
if fileExt <> ".gif" then
fileExt = ".jpg" ' indtil der kommer png support
jpeg.save Path + "\picture_" + cstr(picturenumber) + fileExt
else
set gif = Server.CreateObject("Persits.Jpeg").gif
Gif.addimage jpeg , 0 , 0
gif.save Path + "\picture_" + cstr(picturenumber) + fileExt
set gif = nothing
end if
end if
Response.Write "Picture saved " + Path + "\picture_" +
cstr(picturenumber) + fileExt + " <br/>"
Response.Write "Width: " + cStr(jpeg.Width) + " height: " +
cStr(jpeg.Height) + "<br/>"
PictureWidth = jpeg.Width
PictureHeight = jpeg.Height
Response.Write "tf_Width: " + cStr(Thumbwidth) + " tf_height: " +
cStr(Thumbheight) + "<br/>"
if ( jpeg.Width/jpeg.Height >= Thumbwidth / Thumbheight ) or
( rs("ThumbnailType") > 0 ) then
if ( rs("ThumbnailType") = 3 or rs("ThumbnailType") = 4 ) then
if Thumbwidth * jpeg.Height \ jpeg.Width < Thumbheight then
Thumbwidth = Thumbheight * jpeg.Width \ jpeg.Height
else
Thumbheight = Thumbwidth * jpeg.Height \ jpeg.Width
end if
else
Thumbheight = Thumbwidth * jpeg.Height \ jpeg.Width
end if
else
Thumbwidth = Thumbheight * jpeg.Width \ jpeg.Height
end if
Response.Write "t_Width: " + cStr(Thumbwidth) + " t_height: " +
cStr(Thumbheight) + "<br/>"
jpeg.Width = Thumbwidth
jpeg.Height = Thumbheight
if fileExt <> ".gif" then
if fileExt = ".png" then
jpeg.save Path + "\thumb_" + cstr(picturenumber) + fileExt + ".jpg"
else
jpeg.save Path + "\thumb_" + cstr(picturenumber) + fileExt
end if
else
set gif = Server.CreateObject("Persits.Jpeg").gif
Gif.addimage jpeg , 0 , 0
gif.save Path + "\thumb_" + cstr(picturenumber) + fileExt
set gif = nothing
end if
SQL = "INSERT INTO Pictures VALUES (?,?,?,?,?,?,?,?,?,?,now,now,?,?)"
Parameters(0) = Upload.Form("GalleryName")
Parameters(1) = Session("Loginuser")
Parameters(2) = rs("NumberOfPictures") + 1
Parameters(3) = PicturePath
Parameters(4) = Upload.Form("PictureHead")
Parameters(5) = Upload.Form("PictureText")
Parameters(6) = PictureWidth
Parameters(7) = PictureHeight
Parameters(8) = Thumbheight \ 2
Parameters(9) = Thumbwidth \ 2
Parameters(10) = fileExt
Parameters(11) = Parameters(2)
Response.Write "p_Width: " + cStr(Parameters(9)) + " p_height: " +
cStr(Parameters(8)) + "<br/>"
Rowsaffected = Query(oConn,SQL,Parameters,11)
Response.Write "rows affected(insert) " + cStr(Rowsaffected)
SQL = "UPDATE Galleries SET NumberOfPictures=NumberOfPictures+1 WHERE
GalleryName = ? AND GalleryOwner = ? "
Parameters(0) = Upload.Form("GalleryName")
Parameters(1) = Session("Loginuser")
Rowsaffected = Query(oConn,SQL,Parameters,2)
Response.Write "rows affected(update) " + cStr(Rowsaffected)
rs.close
set rs = nothing
oConn.Close
set oConn = nothing
%>
</body>
</html>
............................
--
Med venlig hilsen
Stig Johansen