PHP从application / octet流创建图像 [英] PHP create image from application/octet stream
问题描述
我的应用程序是从内容类型为application / octet-stream的移动设备发送给它的图像。
My application is having images sent to it from mobile devices with the content-type "application/octet-stream".
我需要使用以下方法处理这些图像GD库,这意味着我需要能够从数据中创建一个图像对象。
I need to process these images using the GD library, which means I need to be able to create an image object from the data.
通常,我一直在使用imagecreatefromjpeg,imagecreatefrompng,imagecreatefromgif等来处理从Web表单上传的文件,但是当我作为application / octet-stream来找我时,这些文件似乎不起作用。
Typically, I have been using imagecreatefromjpeg, imagecreatefrompng, imagecreatefromgif, etc, to handle files uploaded from web forms, but these don't seem to work when coming to me as application/octet-stream.
关于如何实现目标的任何想法?
Any ideas on how I can achieve my goal?
编辑
这是我用来创建图像标识符的代码...我的处理程序在整个过程中完美运行我的网站,我可以告诉我的网站和iOS数据之间的唯一区别是内容类型
Here is the code I use to create the image identifier...my handler works perfectly throughout my site, the only difference I can tell between my site and the data from the iOS is the content-type
public function open_image($path) {
# JPEG:
$im = @imagecreatefromjpeg($path);
if ($im !== false) { $this->image = $im; return $im; }
# GIF:
$im = @imagecreatefromgif($path);
if ($im !== false) { $this->image = $im; return $im; }
# PNG:
$im = @imagecreatefrompng($path);
if ($im !== false) { $this->image = $im; return $im; }
$this->error_messages[] = "Please make sure the image is a jpeg, a png, or a gif.";
return false;
}
推荐答案
简单:)
$image = imagecreatefromstring( $data );
具体来说:
$data = file_get_contents($_FILES['myphoto']['tmp_name']);
$image = imagecreatefromstring( $data );
这篇关于PHP从application / octet流创建图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!