2012-12-19 55 views
1

道歉,如果這看起來不正確,或者是沒有意義的,但是沒有辦法做到以下後...使用PHP,存儲圖像HTML到變量提交

<form id="form1" name="form1" method="post" action="index.php"> 
    <img id="image1" src="URL" name="image1" width="138" height="79" border="0" /> 
    <input name="save" type="hidden" id="save" value="true" /> 
    <input type="submit" name="button" id="button" value="Update" /> 
    </form> 

每當有人提交形式,下面會被存儲到一個變量...

<img id="image1" src="URL" name="image1" width="138" height="79" border="0" /> 

喜歡的東西...

$image1 = <img id="image1" src="URL" name="image1" width="138" height="79" border="0" /> 
+0

是你想要捕捉的圖像只是網址是什麼? – Ben

+0

理想情況下,整個事情「」謝謝 – Richard

+0

我很難成像一個用例,這是正確的做法。如果您存儲了該值,並且再次顯示該值,那麼對於XSS原因將會非常危險。如果您在存儲之前嘗試清理它,那麼爲什麼不從一些參數列表生成它(即保存URL和任何其他重要參數,如寬度或寬高比),並在保存之前生成標記,或者只是保存參數。 –

回答

1

你可以通過添加HTML作爲一個隱藏的表單元素來實現:

<form id="form1" name="form1" method="post" action="?"> 
    <img id="image1" src="URL" name="image1" width="138" height="79" border="0" /> 

    <input type="hidden" name="image1" value='<img id="image1" src="URL" name="image1" width="138" height="79" border="0" />' /> 

    <input name="save" type="hidden" id="save" value="true" /> 
    <input type="submit" name="button" id="button" value="Update" /> 
</form> 

然後,它可作爲$_POST['image1']