Jump to content

Image tag NOT refreshing after upload


Recommended Posts

Hi Everyone...I am currently using Pure Asp Upload to upload images onto the server. Everything is working fine but the image placeholder does not show the newly uploaded image until I manually press the Internet Explorer Refresh button. I have tried to trigger an asp and/or javascript page reload but nothing. I am not too crazy about the idea about using a F5 Sendkeys event and would like to stay away from that option. Here is the code that is triggered after the submit button is clicked.If the file browser is empty, the code will only update the user information otherwise the new image file is updated erasing the old image.

<%Dim DestinationPathDestinationPath = Server.MapPath("\products\")'Create upload form'Using Huge-ASP file upload'Dim Form: Set Form = Server.CreateObject("ScriptUtils.ASPForm")'Using Pure-ASP file uploadDim Form: Set Form = New ASPForm%><!--#INCLUDE FILE="_upload.asp"--><%Server.ScriptTimeout = 2000Form.SizeLimit = 10*&H100000 'multiply by ten to set limit to 10mbIf Form.State = 0 Then 'Completted                 '***This part is triggered after the submit button is triggered from <form method="POST" ENCTYPE="multipart/form-data"> form	Dim intItemID, objFSO	intItemID = trim(Form("UniqueID").Value)  'value from text field	imgSource = Form("Upload_Image").FileName   '****extract image filename from file browser		DestinationPath = DestinationPath & "/" & intItemID & "/"		EditRecord (DestinationPath)		'*********If user selects a new image file to upload, then 	If Form("Upload_Image").FileName <> "" then		Set objFSO = Server.CreateObject("Scripting.FileSystemObject")		objFSO.DeleteFile DestinationPath & "*.*" '****Clean up temp Upload folder		Form.Files.Save DestinationPath		'###########Resize the image###################		Set Img = CreateObject("WIA.ImageFile")		Set IP = CreateObject("WIA.ImageProcess")		Img.LoadFile DestinationPath & imgSource		IP.Filters.Add IP.FilterInfos("Scale").FilterID		IP.Filters(1).Properties("MaximumWidth") = 1024		'*****Set max height or width		IP.Filters(1).Properties("MaximumHeight") = 1024	'the other side will adjust accordingly		Set Img = IP.Apply(Img)		Img.SaveFile DestinationPath & intItemID & ".jpg" 'generate new image size with same name as itemID		Set Img = Nothing		Set IP = Nothing		objFSO.DeleteFile DestinationPath & imgSource '****delete original image		Set objFSO = nothing		 [color="#FF0000"]Response.Write "<script language='JavaScript'>document.location.reload(true);</script>" [color="#FF0000"]Here is where the refresh event is triggered in javascript[/color]	End If	ElseIf Form.State > 10 then  Const fsSizeLimit = &HD  Select case Form.State		case fsSizeLimit: response.write  "<br><Font Color=red>Source form size (" & Form.TotalBytes & " exceeds form limit (" & Form.SizeLimit & "</Font><br>"		case else response.write "<br><Font Color=red>Some form error.</Font><br>"  end SelectEnd If'Form.State = 0 thenFunction EditRecord (DestinationPath)dim oRs, strItemID, strTitle, strDescription, intPrice, strCategory, imgSource	'******retrieve txtbox values into variables	strItemID = Lcase(trim(Form("UniqueID").Value))	strTitle = trim(Form("Title").Value)	strDescription = trim(Form("Product_Description").Value)	intPrice = trim(Form("Price").Value)	strCategory = trim(Form("Category").Value)	'imgSource = Form("file1").FileName	If Form("Upload_Image").FileName <> "" then	imgSource = strItemID & ".jpg"	End If	'********************************************	Set objRS=Server.CreateObject("ADODB.Recordset")	Set objRS.ActiveConnection=objConn	objRS.CursorType=adOpenDynamic	objRS.LockType=adLockOptimistic	objRS.Open "SELECT * FROM Product WHERE ([itemID] ='" & strItemID & "')",objConn		objRS("ItemID")=strItemID		objRS("Title")=strTitle		objRS("Description")=strDescription		objRS("Price")=intPrice		objRS("Category")=strCategory		If Form("Upload_Image").FileName <> "" then		objRS("imgSource")=imgSource		End If		objRS("ListDate")=Now()		objRS.updateEnd Function%>

Here is the code for the Image Placeholder in the <body> which shows the current image but will only show the new image when I manually press the browser's refresh button. Can anyone suggest a way to refresh the image after the new image is uploaded to the server? Thanks!!!

<div id="image"><img src="<%= "\products\" & (objRs("ItemID")) & "\" & (objRs("imgSource"))%>" border="0" width="50%" alt='' title="<%Response.Write objRS("Title")%>" />

Edited by holsy
Link to post
Share on other sites

I have figured it out. The old image was cached in the browser even though my code made it not to cache. The fact that the image name remained the same even though the new image is on the server, the browser did not recognize the change. A simple way around this is to append the current date and time at the end of the image tag src= querystring like this for example:<img src="<%= "\products\" & (objRs("ItemID")) & "\" & (objRs("imgSource")) & "?" & Now() %>" border="0" width="50%" />This way you are telling the browser to check for the most recent image on each reload.Cheers

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...