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

aspjpeg error

Status
Not open for further replies.

s4dadmin

Programmer
Apr 27, 2003
107
0
0
US
I am using aspjpeg to create thumbnails and reduce original image size. I have a script that can upload up to 5 images at a time. Another script handles the form and uses the aspjpeg component to alter the images then updates a database with the paths, size, length, width, etc. I get an error depending on how many images I uploaded. If I upload all 5 images everything goes through smoothly, however if I upload less than 5 files I can get a different error everytime. Examples of the error can be unable to open file and this is because the component would save a 0 byte file and something about Open Binary. Don't have exact examples of errors but I am using jpg and gif files only. Here is the code for the form and the code for the processing page. Can anyone help me?

Form page
Code:
<form action="process_event_images.asp" method="post" enctype="multipart/form-data" name="form1" id="form1">
                    <table width="100%" border="0" cellspacing="0" cellpadding="5">
                      <tr> 
                        <td colspan="2" align="center" class="click">Upload Event 
                          Images</td>
                      </tr>
                      <tr> 
                        <td colspan="2">&nbsp;</td>
                      </tr>
                      <tr> 
                        <td colspan="2" class="click">Image 1 <input type="file" name="file1" /></td>
                      </tr>
                      <tr> 
                        <td colspan="2" class="click">Image 2 <input type="file" name="file2" /></td>
                      </tr>
                      <tr> 
                        <td colspan="2" class="click">Image 3 <input type="file" name="file3" /></td>
                      </tr>
                      <tr> 
                        <td colspan="2" class="click">Image 4 <input type="file" name="file4" /></td>
                      </tr>
                      <tr> 
                        <td colspan="2" class="click">Image 5 <input type="file" name="file5" /></td>
                      </tr>
                      <tr> 
                        <td align="center"><input type="button" name="Preview" value="Preview" onclick="uploadPreview();" /></td>
                        <td align="center"><input type="submit" name="Submit" value="Upload" onclick="Add();" /></td>
                      </tr>
                      <tr> 
                        <td colspan="2" class="click"><a href="index.asp">Back 
                          To Admin Home</a></td>
                      </tr>
                    </table>
                  </form>

Process Page
Code:
<%Option Explicit%>
<%On Error Resume Next%>
<%
'  Variables
'  *********
   Dim mySmartUpload
   Dim file
   Dim intCount
 Dim hits
 hits = 0
 intCount=0
 Dim strSQL
 Dim fs
 Dim strTemp
 Dim strName
 Dim jpeg
 Dim SavePath
 Dim L
 Dim thumbName
 Dim originalSavePath
 Dim originalW
 Dim originalH
 Dim adjustW
 Dim adjustH
 Dim thumbSavePath
'  Object creation
'  ***************
   Set mySmartUpload = Server.CreateObject("aspSmartUpload.SmartUpload")

'  Upload
'  ******
   mySmartUpload.Upload
   mySmartUpload.AllowedFilesList = "jpg,jpeg,gif,png,bmp,tiff"
mySmartUpload.DeniedFilesList = "exe,bat,asp,com,zip,doc"
mySmartUpload.DenyPhysicalPath = True
Set jpeg = Server.CreateObject("Persits.Jpeg")
Set fs = CreateObject("Scripting.FileSystemObject")
thumbSavePath = "/images/thumbnails/"
originalSavePath = "/images/events/"
'  Select each file
'  ****************
   For each file In mySmartUpload.Files
   '  Only if the file exist
   '  **********************
      If not file.IsMissing Then
      '  Save the files with his original names in a virtual path of the web server
      '  **************************************************************************
        strTemp = fs.GetBaseName(fs.GetTempName)
		strTemp = Right(strTemp, Len(strTemp) - 3)
		strName = File.FileName
		strName = strTemp + strName
	    End If

		SavePath = originalSavePath & strName
	     file.SaveAS(SavePath)
         ' sample with a physical path 
         ' file.SaveAs("c:\temp\" & file.FileName)
		If Err Then 
			Response.Write("<strong>Unsuccessful upload: </strong>" & Err.Description & " " & CStr(Err.Number)& " " & Err.Source & "<br />")
			Response.Write("<strong>Click the back button to try again.</strong>")
			Response.End
		Else 

		jpeg.Open Server.MapPath(SavePath)
		originalW = jpeg.OriginalWidth
		originalH = jpeg.OriginalHeight
L = 100
If jpeg.OriginalWidth > jpeg.OriginalHeight Then
   jpeg.Width = L
   jpeg.Height = jpeg.OriginalHeight * L / jpeg.OriginalWidth
Else
   jpeg.Height = L
   jpeg.Width = jpeg.OriginalWidth * L / jpeg.OriginalHeight
End If
		jpeg.Sharpen 1, 250
		'Draw frame: black, 2-pixel width
		jpeg.Canvas.Pen.Color = &H000000
		jpeg.Canvas.Pen.Width = 2
		jpeg.Canvas.Brush.Solid = False
		jpeg.Canvas.Bar 1, 1, jpeg.Width, jpeg.Height
		adjustW = jpeg.Width
		adjustH = jpeg.Height
		If UCase(Right(strName, 3)) <> "JPG" Then
	      strName = strName & ".jpg"
	    End If
		thumbName = "thumb" + strName
		SavePath = thumbSavePath & thumbName
		jpeg.Save Server.MapPath(SavePath)
		jpeg.Close  
		SavePath = originalSavePath & strName
		jpeg.Open Server.MapPath(SavePath)
L = 500
If jpeg.OriginalWidth > jpeg.OriginalHeight Then
   jpeg.Width = L
   jpeg.Height = jpeg.OriginalHeight * L / jpeg.OriginalWidth
Else
   jpeg.Height = L
   jpeg.Width = jpeg.OriginalWidth * L / jpeg.OriginalHeight
End If
		jpeg.Sharpen 1, 250
		'Draw Text
		jpeg.Canvas.Font.Color = &HFF0000
		jpeg.Canvas.Font.Family = "Courier New"
		jpeg.Canvas.Font.Bold = True
		'jpeg.Canvas.Font.Quality = 4
		'jpeg.Canvas.Font.BKMode = "Opaque"
		jpeg.Canvas.Font.Size = 25
		jpeg.Canvas.Print 10, 10, "512ryders.com"
		'Draw frame: black, 2-pixel width
		jpeg.Canvas.Pen.Color = &H000000
		jpeg.Canvas.Pen.Width = 2
		jpeg.Canvas.Brush.Solid = False
		jpeg.Canvas.Bar 1, 1, jpeg.Width, jpeg.Height
		SavePath = originalSavePath & strName
		jpeg.Save Server.MapPath(SavePath)
		jpeg.Close
		
		 strSQL = "INSERT INTO tbl_Images (imageFileName, imageFilePath, imageFileSize, imageHits, imageWidth, imageHeight, thumbFileName, thumbFilePath, thumbWidth, thumbHeight) VALUES ('" & strName & "','"&originalSavePath&"','" & File.Size & "','" & hits & "','" & originalW & "','" & originalH & "','"& thumbName & "','"&thumbSavePath&"','" & adjustW & "','" & adjustH & "');"
		 adoCon.Execute(strSQL) 
		 
		 Response.Write(file.Name & ", ")
         Response.Write("Size = " & file.Size & "bytes, ")
         Response.Write(strName & ", ")
         Response.Write(file.ContentType & "<br />")
		 'Response.Write("<table><tr><td><img src='../images/thumbnails/"&thumbName&"' /></td>")
		 'Response.Write("<td><img src='../images/events/"&strName&"' /></td></tr></table>")

         intCount = intCount + 1
      End If
   Next
Set fs = Nothing
Set jpeg = Nothing

%>
 		<!--#include file="../includes/closeconn.asp"-->		

					  </td>
                    </tr>
                    <tr> 
                      <td class="click"> <%Response.Write("<BR>" & mySmartUpload.Files.Count & " files could be uploaded.<BR>")%> </td>
                    </tr>
                    <tr>
                      <td class="click">   <%Response.Write(intCount & " file(s) uploaded.<BR>")
%></td>

Quincy
 
It should be as simple as checking to see see if the filename has been entered. We use AspJpeg on our website, but we use it to only upload & format one image at a time. We did have to add error checking to ensure that a blank form was not submitted.
 
In my code I have this line
Code:
If not file.IsMissing Then

Is this what you mean by checking to see if the filename has been entered?

Quincy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top