Hello,
I use an ASP.NET script on my website to upload images (complete script
is listed at the end of this message).
Now, I want to limit the size (in width and height, but also in bytes).
For example, if the image is max. 400 pixel in height or max. 400 pixel
width or max. 100 Kb. The image is not uploaded. How can I do this?
Additionally, I also want to resize the images to a valid size when
they are to big than the specified size (max. 400 pixel in height or
max. 400 pixel width or max. 100 Kb). Is there a function or way to do
this in ASP.NET?
Finally, I want to add a text under each image (like: "This image
copyrighted by ..."). This text should be part of the image, so not
just put a HTML text under it.
I know that you can buy components to exactly do want I want to do. For
example: http://64.39.14.230/ig-asp/common/abcphotoadmin.asp
The problem is that I need to do it myself because my provider does not
allow me to install DLL-files on his server.
******************* START UPLOAD.ASPX FILE **********************
<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.IO" %>
<script runat="server">
Sub SubmitButton_Click(Source As Object, e As EventArgs)
If Not (oFile.PostedFile Is Nothing) Then
Try
'Declare variables
Dim strFileName As String
Dim strFilePath As String
Dim strFolder As String
Dim strPicType As String
Dim strPicSize As String
'Set Upload Folder
strFolder = "D:\Inetpub\wwwroot\upload\"
'Get the name of the file that is posted
strFileName = oFile.PostedFile.FileName
strFileName = Path.GetFileName(strFileName)
strFilePath = strFolder & strFileName
'Validate that it is an image file
strPicType = oFile.PostedFile.ContentType
strPicSize = oFile.PostedFile.ContentLength
If (strPicType="image/jpeg" or strPicType="image/gif" or
strPicType="image/pjpeg" or strPicType="image/bmp") then
'Save file
oFile.PostedFile.SaveAs(strFil**ePath)
Span.InnerHtml = "De afbeelding werd succesvol
bewaard!<BR><IMG SRC='http://www.a-random-website.co**m/upload/" &
strFileName & "'><BR>" & strPicSize & "."
Else
Span.InnerHtml = "De afbeelding is niet van het formaat
GIF, JPG,
JPEG of BMP!"
End If
Catch ex As Exception
Span.InnerHtml = "Er is een fout opgetreden bij het
bewaren van de afbeelding. Probeer het eens opnieuw."
End Try
End If
End Sub
</script>
<html>
<head>
<title>Title</title>
</head>
<body>
<FONT FACE="Trebuchet MS, Arial, Helvetica, Verdana" SIZE="2"
COLOR="#4E69B0">
<form runat="server" enctype="multipart/form-data">
Selecteer de afbeelding die je wenst toe te voegen:<br />
<input type="file" id="oFile" runat="Server"><br/>
<input type="submit" id="Submit" runat="Server"
value="Upload File" OnServerClick="SubmitButton_Cl**ick">
<p>
<span id="Span" runat="Server" />
</form>
</FONT>
</body>
</html>
******************* END UPLOAD.ASPX FILE **********************
Thanks!