简体   繁体   English

上载时image_width和image_height为空白(PHP / Codeigniter)

[英]image_width & image_height are blank on upload (PHP / Codeigniter)

I have an intermittent image uploading issue that I can't seem to track down an answer for. 我有一个间歇性的图像上传问题,似乎无法找到答案。 I'm using Codeigniter, but this may just simply be a PHP related issue. 我正在使用Codeigniter,但这可能只是与PHP相关的问题。

I'm doing simple single image uploads. 我正在做简单的单张图片上传。 The files upload just fine in all cases. 在所有情况下,文件上传都很好。 Then I attempt to access the upload data to determine height and width. 然后,我尝试访问上传数据以确定高度和宽度。 Most of the upload data is populated, but height and width are blank. 大部分上传数据已填充,但高度和宽度为空白。 This only happens for some images, others work just fine. 这仅适用于某些图像,而其他图像则可以正常工作。

Anyone point me in the right direction? 有人指出我正确的方向吗? Any thoughts? 有什么想法吗? There's something I'm not seeing here. 我这里没看到什么。

Here's an example of the upload data I receive: 这是我收到的上传数据的示例:

[upload_data] => Array (
  [file_name] => example.jpg
  [file_type] => image/jpe
  [file_path] => path/to/file/
  [full_path] => path/to/file/example.jpg
  [raw_name] => example
  [orig_name] => example.jpg
  [client_name] => myPic.jpg
  [file_ext] => .jpg
  [file_size] => 568.02
  [is_image] => 1
  [image_width] =>
  [image_height] =>
  [image_type] =>
  [image_size_str] =>
)
list($width, $height, $type, $attr) = getimagesize("path/for/the/file");

http://www.php.net/manual/zh/function.getimagesize.php

Through a lot of trial and error I found the cause of the issue, but not the solution. 通过大量的试验和错误,我找到了问题的原因,但没有找到解决方法。 However, from what I can tell, the cause is linked to Amazon's S3 storage, not CodeIgniter or PHP. 但是,据我所知,其原因与亚马逊的S3存储有关,而不是CodeIgniter或PHP。 So I'm considering this question answered since it's tagged as a PHP/Codeigniter question. 因此,我正在考虑回答这个问题,因为它被标记为PHP / Codeigniter问题。

In a nutshell, here's what I found. 简而言之,这就是我所发现的。 Codeigniter uses 'getimagesize' just like you would in straight PHP. Codeigniter使用'getimagesize'就像在直接PHP中一样。 So I started testing outside of CI just calling getimagesize on different JPEGS. 因此,我开始在CI外部进行测试,只是在不同的JPEG上调用getimagesize。

When accessing images stored locally on the server/instance, everything works fine, no matter what their properties. 当访问本地存储在服务器/实例上的图像时,无论其属性如何,一切都可以正常工作。

When I access images on Amazon's S3 storage, the JPEGS whose "color representation" property is set to "sRGB" cause getimagesize to return false. 当我访问Amazon S3存储上的图像时,其“颜色表示”属性设置为“ sRGB”的JPEGS导致getimagesize返回false。 Those without the property set work just fine. 那些没有属性设置的就可以了。

So something about storing the images on S3 is causing an issue. 因此,有关在S3上存储图像的某些问题引起了问题。 But that's the subject of another post. 但这是另一篇文章的主题。

Thanks for your input on this one everyone. 感谢大家对此的投入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM