duanbinian2243 2016-05-18 10:38
浏览 46
已采纳

要求用户上传图像或使用远程图像

I'm working on a portal that requires users to upload the images which wil be shown in a certain HTML pages. What should be the good practice here ?

  1. Should I avoid uploading and ask users to give their own URL for the images ?

  2. Ask users to upload image files.

Since we know, an image can be a deadly one if it contains code injection, but what about the remote ones, are they secure ?

Thanks

  • 写回答

3条回答 默认 最新

  • dongshaidu2456 2016-05-18 11:06
    关注

    It depends on your website consistency. Uploading is much better than entering URL for example if the targeted audience is a professional clients they would prefer uploading as it would be difficult to explain to them what is a remote url and how to get it. But uploading is a more traditional way and feels more easy.

    On the other hand if most of your targeted audience is internet users then there might be no need to give upload option. But as I said uploading feels much more natural and easy to users. It also depends on the type of images, if the images are the user's avatar then uploading would fit and if the users are adding images to your website to only share images they found from other websites then remote url would be more appropriate.

    Both uploading and fetching remote ones to your server could be deadly, but if you use remote ones just to store the urls in your database then it will create no security problem.

    So if you want upload feature or storing the remote images to your server you must do some certain steps to ensure the security of your server:

    1. Verify the file extension and mime to be of valid image. (Don't rely only on this.)

    2. Verify it's a valid image file (using php getimagesize)

    3. Resize and copy the image into a new image object. And store that image into your server.

    4. The folder where you are going to store must have all kinds of code executions disabled by using .htaccess (SetHandler default-handler)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址