作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试上传图像,更改其大小,然后将结果写入 MySQL 数据库。基本代码:
// load original image
$image = imagecreatefromjpeg($file); // load original image
// create new image
$newImage = imagecreatetruecolor($newWidth, $newHeight);
// copy original to new, changing size
imagecopyresampled($newImage, $image, 0, 0, 0, 0, $newWidth, $newHeight,$origWidth, $origHeight);
// save new image in database (in a BLOB field)
mysql_query("UPDATE myTable SET Photo='" . mysql_escape_string($newImage) . "' WHERE keyField=2");
但没有存储任何内容。 $newImage 似乎是尺寸正确的有效图像。我做不到什么?
最佳答案
作为@Wayne said 。我建议将图像保存在文件系统中并将文件路径保存在数据库中
这是将图像复制到文件系统的代码
$imagepath="C:/your/file/complete/path";
if(isset($_FILES["file"])){
move_uploaded_file($_FILES["file"]["tmp_name"], $imagepath);
mysql_query("UPDATE myTable SET photo_path='" .$imagepath. "' WHERE keyField=2");
}
编辑:如果您确实需要保存在数据库中,请检查 this详细说明
关于php - 如何在 MySQL 中存储内存中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29546418/
我是一名优秀的程序员,十分优秀!