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条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度