1. <small id='F0NCS'></small><noframes id='F0NCS'>

    <i id='F0NCS'><tr id='F0NCS'><dt id='F0NCS'><q id='F0NCS'><span id='F0NCS'><b id='F0NCS'><form id='F0NCS'><ins id='F0NCS'></ins><ul id='F0NCS'></ul><sub id='F0NCS'></sub></form><legend id='F0NCS'></legend><bdo id='F0NCS'><pre id='F0NCS'><center id='F0NCS'></center></pre></bdo></b><th id='F0NCS'></th></span></q></dt></tr></i><div id='F0NCS'><tfoot id='F0NCS'></tfoot><dl id='F0NCS'><fieldset id='F0NCS'></fieldset></dl></div>
      <bdo id='F0NCS'></bdo><ul id='F0NCS'></ul>

  2. <legend id='F0NCS'><style id='F0NCS'><dir id='F0NCS'><q id='F0NCS'></q></dir></style></legend>
  3. <tfoot id='F0NCS'></tfoot>

      图片上传安全 - 使用 GD 重新处理

      时间:2023-10-02
        <legend id='jLqmU'><style id='jLqmU'><dir id='jLqmU'><q id='jLqmU'></q></dir></style></legend>

              • <bdo id='jLqmU'></bdo><ul id='jLqmU'></ul>
                  <tbody id='jLqmU'></tbody>
              • <i id='jLqmU'><tr id='jLqmU'><dt id='jLqmU'><q id='jLqmU'><span id='jLqmU'><b id='jLqmU'><form id='jLqmU'><ins id='jLqmU'></ins><ul id='jLqmU'></ul><sub id='jLqmU'></sub></form><legend id='jLqmU'></legend><bdo id='jLqmU'><pre id='jLqmU'><center id='jLqmU'></center></pre></bdo></b><th id='jLqmU'></th></span></q></dt></tr></i><div id='jLqmU'><tfoot id='jLqmU'></tfoot><dl id='jLqmU'><fieldset id='jLqmU'></fieldset></dl></div>

                <tfoot id='jLqmU'></tfoot>

                <small id='jLqmU'></small><noframes id='jLqmU'>

                本文介绍了图片上传安全 - 使用 GD 重新处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我听说处理上传图像的最佳方法是使用 GD 库重新处理"它们并保存处理后的图像.参见:PHP图片上传安全检查清单

                我的问题是如何在 GD 中进行这种重新处理"?这究竟是什么意思?我对GD库不是很了解,怕把它搞砸了...

                I've heard that the best way to handle uploaded images is to "re-process" them using the GD library and save the processed image. see: PHP image upload security check list

                My question is how do this "re-processing" in GD? What this means exactly? I don't know the GD library very well and I'm afraid I will mess it up...

                所以如果有人之前做过这件事,你能给我举个例子吗?

                So if anyone who did this before could you give me an example for this?

                (我知道,另一种选择是使用 ImageMagick.对于 ImageMagick,我在这里找到了答案:使用 PHP 从 JPG 中删除 EXIF 数据,但我现在不能使用 ImgMagick.顺便说一句.. 在这种情况下,删除 EXIF 数据意味着完全重新创建图像?)
                (如果有人感兴趣,我正在使用 Zend 框架.)

                (I know, another other option is to use ImageMagick. For ImageMagick I found an answer here: Remove EXIF data from JPG using PHP, but I can't use ImgMagick now. By the way.. removing EXIF data means completely recreate the image in this case?)
                (I'm using Zend Framework if someone interested.)

                推荐答案

                如果用户上传了一个 JPEG 文件,你可以做这样的事情来重新处理它:

                If the user uploads a JPEG file, you could do something like this to reprocess it:

                $newIm = @imagecreatefromjpeg($_FILES['file']['tmp_name']);
                if (!$newIm) {
                    // gd could not create an image from the source
                    // most likely, the file was not a valid jpeg image
                }
                

                然后您可以使用 imagedestroy() 丢弃 $newIm 图像并使用从用户上传的文件,或者从 GD 中保存图像并使用它.保存 GD 图像可能存在一些问题,因为它不是原始图像.

                You could then discard the $newIm image using imagedestroy() and use the uploaded file from the user, or save out the image from GD and use that. There could be some issues with saving the GD image as it is not the original image.

                另一种简单的方法是检查图像文件的标题(前几个字节)以确保其正确;例如,所有 JPEG 文件都以 0xff 0xd8 开头.

                Another simple method would be to check the header (first several bytes) of the image file to make sure it is correct; for example all JPEG files begin with 0xff 0xd8.

                另见imagecreatefromstring(),你也可以使用getimagesize() 对上传的图片运行类似的检查.

                See also imagecreatefromstring(), and you can also use getimagesize() to run similar checks on the uploaded image.

                这篇关于图片上传安全 - 使用 GD 重新处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:将外部脚本与 Zend Framework 集成 下一篇:异常捕获:什么时候不捕获它们?

                相关文章

                最新文章

              • <small id='CHREA'></small><noframes id='CHREA'>

              • <i id='CHREA'><tr id='CHREA'><dt id='CHREA'><q id='CHREA'><span id='CHREA'><b id='CHREA'><form id='CHREA'><ins id='CHREA'></ins><ul id='CHREA'></ul><sub id='CHREA'></sub></form><legend id='CHREA'></legend><bdo id='CHREA'><pre id='CHREA'><center id='CHREA'></center></pre></bdo></b><th id='CHREA'></th></span></q></dt></tr></i><div id='CHREA'><tfoot id='CHREA'></tfoot><dl id='CHREA'><fieldset id='CHREA'></fieldset></dl></div>

                  <bdo id='CHREA'></bdo><ul id='CHREA'></ul>

                  <tfoot id='CHREA'></tfoot>

                  1. <legend id='CHREA'><style id='CHREA'><dir id='CHREA'><q id='CHREA'></q></dir></style></legend>