以下是我的方法將其用於你的意願。
好吧,這可能比你需要更多,但這應該讓你在這個圖像刪除問題的東西某處。
這是你的代碼。但我把它分成兩頁。當然,我不能看到這個頁面上還有什麼內容和表單處理的東西,所以我們將從你給我們的東西開始。
<cfset mediapath = expandpath('../images/about')>
不錯的使用structKeyExists的():)
<cfif structKeyExists(form,"image") and len(form.image)>
在這裏,我會停下來,建議你限制你的 上傳到剛剛.GIF,.JPEG,爲.jpg,.png (你的主圖像類型),以防止上傳任何 和每種文件類型。我在下面添加了一個接受參數。
<cffile action="upload"
filefield="image"
destination="#MediaPath#"
nameconflict="makeunique"
accept="image/*">
<cfimage name="uploadedImage"
source="#MediaPath#/#file.serverFile#" >
好了上傳文件允許單獨的擔憂
在這一點上我會問他們,如果他們想預覽該文件。如果他們點擊「預覽」,將它們帶到preview.cfm頁面。
然後你有一個文件名,如果你沒有別的東西(比如ID或主鍵),你需要通過。
所以我把這個方便,花花公子腳本出在其網站上的Adobe ColdFusion的文檔中,我會用這個來把你的文件名變成「別的東西」;)
<cfscript>
theKey="123abc";
theKey=generateSecretKey("AES")
superDuperSecretSoDontTell=encrypt(file.serverFile, theKey, "AES", "hex");
</cfscript>
<a href="preview.cfm?fileName=#superDuperSecretSoDontTell#&theKey=#theKey#">Let's send this piggy!</a>
和您去到預覽頁面...
<cfoutput>
(朝上)這是pageA.cfm (朝下)這是pageB.cfm
現在我有下面的代碼的其餘部分,讓拉基於闖關查詢字符串文件變量/值對。
<cfscript>
IWannaKnowTheSecret=decrypt(url.fileName, url.theKey, "AES", "hex");
</cfscript>
在這裏,我會停下來,建議你限制你的 上傳到剛剛.GIF,.JPEG,爲.jpg,.png (你的主要類型的圖像),以防止上傳任何 和everyfile類型。我在下面添加了一個接受參數。
<cffile action="read" file="#MediaPath##IWannaKnowTheSecret#" variable="uploadedImage">
<cfset imagesize = 320>
有趣的句柄在這裏。因此,您將兩個值中較大的一個取爲 ,並使用該值來減小大小。整齊。
<cfif uploadedImage.width GT uploadedImage.height>
<cfset percentage = (imagesize/uploadedImage.width)>
<cfelse>
<cfset percentage = (imagesize/uploadedImage.height)>
</cfif>
<cfset newWidth = round(uploadedImage.width * percentage)>
<cfset newHeight = round(uploadedImage.height * percentage)>
然後做一個形式是這樣的:
<form action="" method="post" enctype="multipart/form-data">
Your current Image:
<cfoutput>
Name: #uploadedImage#<br>
<img src="../images/about/#uploadedImage#" style="height:#newHeight#; width:#newWidth#;">
</cfoutput>
Do you want to remove this?<br>
<input type="checkbox"
name="removeImage"
value="1" />: Remove the logo image</cfif><br />
Wnat to replace your image?<br>
<input type="file" name="replacementImage"> (
<input type="hidden"
name="uploadedImage"
value="<cfoutput>#uploadedImage#</cfoutput>">
<input type="submit" value="submit" name="submit"
</form>
<a href="#" onclick="javascript:window.history.back(-1);return false;">Cancel and go back</a>
如果他們繼續要修復的圖像或更換。提交然後你可以使用這樣的東西。 然後我們刪除...
如果提交的文件replacementImage填充,然後我們添加該文件。
有你有它...
你一些分隔條件的擔憂。 您正在給予改進的選項。 您允許更改或不更改。 你正在給他們出去回到你想要的地方。
編輯:這是證明的編碼和解碼的東西(如果你想發揮它:「怎麼會變成這樣的臨時文件被刪除」?
<cfscript>
theKey="123abc";
theKey=generateSecretKey("AES");
superDuperSecretSoDontTell=encrypt("monkeytoots", theKey, "AES", "hex");
</cfscript>
<cfoutput><a href="?fileName=#superDuperSecretSoDontTell#&theKey=#theKey#">Let's send this piggy!</a></cfoutput>
<cfif isdefined("url.fileName") and isdefined("url.theKey")>
<cfscript>
IWannaKnowTheSecret=decrypt(url.fileName, url.theKey, "AES", "hex");
</cfscript>
<cfoutput>
#IWannaKnowTheSecret#
</cfoutput>
</cfif>
最明顯的答案是「用'< cffile action =「delete」>'「,根據信息量的限制,你可以得到一個好答案。你究竟在這裏問什麼? –
」否「也是一個提交。可以在服務器端檢查按鈕被按下並執行相應的操作 –
兩個提交按鈕可能會導致意想不到的結果,我建議選擇一個或單選按鈕來代替 –