converting blob image to file in php

前端 未结 2 1342
清酒与你
清酒与你 2021-01-04 14:17

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

相关标签:
2条回答
  • 2021-01-04 14:38

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

    and there you go.

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

    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.

    0 讨论(0)
  • 2021-01-04 14:43

    Try just writing it to a file with an image/[fill-in-the-blank] mimetype. Or maybe imagecreatefromstring will work. (NOT sure about any of these)

    Or you can find another way to resize the images.

    0 讨论(0)
提交回复
热议问题