[QUOTE=slippers;23650]I am getting a little confused here, can I resize the image without saving it but still use file.filename (I thought file.filename grabbed the name of the image just uploaded)
The upload.save method does need to be called - if you omit the path it does a memory save so you can examine the filename, form fields etc before you save the file to disk.
Try the following - if you reresh the page a few times you should get some new versions.
Code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html><head><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' /> <style type="text/css"> <!-- #loading { width: 200px; height: 100px; background-color: #c0c0c0; position: absolute; left: 50%; top: 50%; margin-top: -50px; margin-left: -100px; text-align: center; } --> </style> <script type="text/javascript"> <!-- Begin document.write('<div id="loading"><br><br>Please wait...</div>'); window.onload=function(){ document.getElementById("loading").style.display="none"; } // End --> </script> </head> <body > <% PathPrefix = Server.MapPath("/Pics/products/") & "\" & Request.Cookies("AdminId") & "-" ' Create an instance of AspUpload object Set Upload = Server.CreateObject("Persits.Upload") Upload.ProgressID = Request.QueryString("PID") Upload.Save ' >>>>>Save to Memory - Now we can access the filename before we save it to disk. Set File = Upload.Files(1) LeftFN=Left(File.Filename,INSTR(File.Filename,".")-1) '- drop '.jpg' 'Make Path+filename unique CT=0 Path=PathPrefix & LeftFN & ".JPG" While Upload.FileExists(Path) CT=CT+1 Path = PathPrefix & LeftFN & "(" & CT & ").JPG" Wend File.saveas(path) ' 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(path) 'only resize if bigger if Jpeg.OriginalWidth > 600 then ' Resize, preserve aspect ratio Jpeg.Width = 600 Jpeg.Height = Jpeg.OriginalHeight * W / Jpeg.OriginalWidth end if jpeg.Save Path end if 'response.redirect "/admin/products/edit-image/?productpicture=" & Path %> </body> </html>


Reply With Quote

Bookmarks