gpt4 book ai didi

php - 使用 class.upload.php 将图像上传到 mysql DB。图像名称没有扩展名

转载 作者:行者123 更新时间:2023-11-29 11:28:00 24 4
gpt4 key购买 nike

我正在尝试使用class.upload.php。它可以工作,但是当我将图像名称存储到 mysql 数据库中时,我没有文件的扩展名(.jpg)。将图像名称与扩展名一起上传到文件夹中。

示例。在文件夹中,我有图像名称 dedafab546ea17dd3093c782a7193e99.jpg...ok

进入数据库,我有 dedafab546ea17dd3093c782a7193e99....没有扩展名。

我不明白为什么......有什么建议吗?谢谢!!

$name        = $_POST['txtName'];
$description = $_POST['mtxDescription'];
$meta_desc = $_POST['metaDescription'];
$parentId = $_POST['hidParentId'];
$name_img = $_FILES['fleImage']['name'];


include('class.upload.php');
$dir_dest="../../images/category/";


$handle = new Upload($_FILES['fleImage']);
if ($handle->uploaded) {

$mainame = $handle->file_dst_name;
$db_name = str_replace(" ","_",$mainame);
$image = md5(rand() * time()) . ".$db_name";
$parts = explode(".",$image);
$extension = end($parts);
$result_big = str_replace("." . $extension,"",$image);

$handle->file_new_name_body = $result_big;
$handle->image_resize = true;
$handle->image_convert = jpg;
$handle->image_x = 358;
$handle->image_ratio_crop = true;
$handle->image_y = 180;
$handle->Process($dir_dest);

// we check if everything went OK
if ($handle->processed) {
header("Location: index.php"); //echo 'image resized';
$handle->clean();


$sql = "INSERT INTO tbl_category (cat_parent_id, cat_name, cat_description, cat_image, meta_desc)
VALUES ($parentId, '$name', '$description', '$result_big', '$meta_desc')";
$result = dbQuery($sql) or die('Cannot add category' . mysql_error());

header('Location: index.php?catId=' . $parentId);

} else {
echo 'error : ' . $handle->error;
}
}
}

最佳答案

以下行将扩展名替换为空

$result_big = str_replace("." . $extension,"",$image); 

关于php - 使用 class.upload.php 将图像上传到 mysql DB。图像名称没有扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37877321/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com