将Blob图像转换为php中的文件 [英] converting blob image to file in php

查看:609
本文介绍了将Blob图像转换为php中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用一个简单的$ _FILES上传脚本将图片从我的iPhone应用程序上传到服务器.但是,图像大小很大,我想在将图像发送到服务器之前调整它们的大小.

I'm currently using a simple $_FILES upload script to upload pictures from my iPhone app to server. The image sizes, however, are large and I'd like to resize them before sending the image to the server.

但是,这样做的缺点是resize函数将它们转换为"blob"图像(据我所知,这是将图像存储在数据库中的一种方式).我希望将文件直接保存到文件系统中.我将如何将blob转换回$ _FILE或找到一个将blob图像保存到光盘的脚本?

The downside of this, however, is that the resize function converts them to "blob" images (which, as I understand it, is a way of storing the image in the database). I'd prefer to save the files directly to the filesystem. How would I go about converting a blob back into a $_FILE or finding a script that saves blob images to disc??

谢谢!

推荐答案

BLOB 二进制图像.一旦将映像放在服务器上,就可以将其写入文件系统.因此,如果您的图片位于变量$ my_blob中,则可以执行

The BLOB is the binary image. You can write that image to your filesystem once it's on your server. So if your image is in the variable $my_blob, you would do something like

file_put_contents('/path/to/new/file_name', $my_blob);

然后您就去了.

您可能想先将文件保存到tmp位置,然后再进行一些检查,然后再将其移动到最终位置(使用PHPs named()函数).

You might want to save the file to a tmp location first, then do some checks on it before you move it to a final location (with PHPs rename() function).

顺便说一句:为什么不只将BLOB保存到DB?如今,这是处理文件的合法方法,这毕竟是BLOB MySQL数据类型的目的.

Btw: why not just save the BLOB to DB? That is a legitimate way of handling files these days, that's what the BLOB MySQL data type is for after all.

这篇关于将Blob图像转换为php中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆