php将数据库里的图片路径取出来,PHP:从base64字符串中获取图像并将其存储在路径中...

这是

PHP函数,它将新数据添加到MySQL数据库中.

**我想在Web服务器上传图像. **

public function addNewCategory($category_title, $strImage) {

// get the image from the base64 string.

$strImage = base64_decode($strImage);

$image = imagecreatefromstring($strImage);

if($image !== false) {

header('Content-Type: image/png');

imagepng($image);

imagedestroy($image);

}

// set the path name of where the image is to be stored.

$path = $_SERVER['SERVER_NAME']."/uploads/".$category_title.".png";

// save the image in the path.

file_put_contents($path, $image);

// insert category and the image path into the MySQL database.

$result = mysqli_query($this->db->connect(), "INSERT INTO category(category_title, path, created_at) VALUES ('$category_title', '$path', NOW())");

if ($result) {

return mysqli_fetch_array($result);

} else {

return false;

}

}

使用该函数,路径变量存储在数据库中,但图像实际上并未存储在路径中.上面的代码有什么问题?

编辑

我将路径名更改为$path = $_SERVER [‘SERVER_NAME’].“/ MyProject / uploads /\”.$category_title.”.png“;.现在数据库中的路径值证明是我所期望的,但似乎图像本身并没有实际放入路径中.

我向数据库添加了一个新行,在浏览器中手动键入路径以检查我发送的图像是否正确存储在路径中,但Web服务器返回错误404.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值