简体   繁体   中英

PHP- how can I store an image into an SQL database without using temporary files?

I'm trying to store an image into an SQL database without using temporary files. I don't want to use temporary files as too many of them could cause problems. I saw this tutorial : but that uses temporary files as does this question and this . I have the image as a php resource and not a file. Trying to put a base64 string of the image in fails as well.I am writing to a blob. Thanks for looking, any help would be appreciated.

Output buffering!

ob_start();
imagejpeg($image_resource);
$image = ob_get_clean();

$image now holds image data you can write to a blob field in your mysql database.

PHP isn't really built to handle long tasks or file uploading.

That means it relies on Apache functions for file upload.

So you have to do as all examples show you : let Apache handle the uploading in a temp directory and only after put the file in database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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