我知道有人回答了與此密切相關的問題,但即使經過深入研究,我仍未找到適用於我的問題的解決方案。只允許我的域名爲我的服務器提供圖片
問題如下:我有一個文件系統,允許我的用戶上傳個人資料圖片,並在未來將整個私人圖片庫。我希望能夠從我自己的網頁中,通過簡單地添加<img src="http://example.org/usercontent/[FOLDERID]/profilepicture.png" />
來獲取這些個人資料圖片。同時我想阻止人們在他們的URL欄中輸入http://example.org/usercontent/[FOLDERID]/profilepicture.png,並直接查看圖片,因爲這些圖片應該只對登錄用戶可見。 這可能嗎?我在我的.htaccess文件中嘗試過使用 <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://(www\.)?example\.org/.*$ [NC] RewriteRule .(gif|jpg|png|jpeg)$ [R,NC,L] </ifModule>
<IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://(www\.)?example\.org/.*$ [NC] RewriteRule .(gif|jpg|png|jpeg)$ [R,NC,L] </ifModule>
,但這會導致我的所有圖像都被阻止,即使我嘗試<img src="http://example.org/usercontent/[FOLDERID]/profilepicture.png" />
,它應該只顯示圖像,因爲圖像標記是寫在我自己的一個頁面上。
我不明白。 'readfile'沒有提示下載?我只想展示圖片,而不是下載它。 –
'readfile'只是將文件傳輸到瀏覽器。由瀏覽器決定如何處理它。通常情況下,如果它位於'
'元素中,則它會將其顯示爲圖像,如果它具有「Content-Disposition:attachment」頭部,它將提供保存。 –
bobince