我使用class.upload.php作为图片。调整大小正确使用名称和扩展名到文件夹,但我有一个问题存储名称到mysql数据库。没有文件扩展名(.jpg,.gif等)......为什么?我该如何解决这个问题? 感谢
/* ========== SCRIPT UPLOAD MULTI IMAGES ========== */
include('class.upload.php');
$dir_dest="../../images/gallery/";
$files = array();
foreach ($_FILES['fleImage'] as $k => $l) {
foreach ($l as $i => $v) {
if (!array_key_exists($i, $files))
$files[$i] = array();
$files[$i][$k] = $v;
}
}
foreach ($files as $file) {
$handle = new Upload($file);
if ($handle->uploaded) {
$mainame = $handle->file_dst_name;
$db_name = str_replace(" ","_",$mainame);
$image1 = md5(rand() * time()) . ".$db_name";
$parts = explode(".",$image1);
$extension = end($parts);
$result_big = str_replace("." . $extension,"",$image1);
$handle->file_new_name_body = $result_big;
$handle->image_resize = true;
$handle->image_x = 460;
$handle->image_ratio_y = true;
// $handle->image_y = 400;
$handle->Process($dir_dest);
//Thumbnail
$db_name = str_replace(" ","_",$mainame);
$image1 = md5(rand() * time()) . ".$db_name";
$parts = explode(".",$image1);
$extension = end($parts);
$result_small = str_replace("." . $extension,"",$image1);
$handle->file_new_name_body = $result_small;
$handle->image_resize = true;
$handle->image_x = 180;
$handle->image_ratio_y = true;
// $handle->image_y = 120;
$handle->Process($dir_dest);
// we check if everything went OK
if ($handle->processed) {
header("Location: index.php"); //echo 'image resized';
$handle->clean();
$query_img="INSERT into tbl_images (file_name, pd_image, pd_thumbnail) VALUES('$nome','$result_big', '$result_small')";
$result2 = dbQuery($query_img);
} else {
echo 'error : ' . $handle->error;
}
}
}
// END SCRIPT UPLOAD MULTI IMAGES
header("Location: index.php");
}
答案 0 :(得分:0)
您已使用str_replace
$result_small = str_replace("." . $extension,"",$image1);
在这里
$result_big = str_replace("." . $extension,"",$image1);
更新以下行只需在末尾添加.$extension
$handle->file_new_name_body = $result_big.$extension;
和
$handle->file_new_name_body = $result_small.$extension;
只需像这样更改查询
$query_img="INSERT into tbl_images (
file_name,
pd_image,
pd_thumbnail
) VALUES (
'$nome',
'{$result_big}.{$extension}',
'{$result_small}.{$extension}')";
我建议您为pd_image
和pd_thumbnail
设置相同的文件名,只需在前面添加thumb_
前缀,这样可以让您的生活变得更轻松。
通过这种方式,您只需在thumb_
前加pd_image
前缀即可访问任何图片缩略图,并且您不必将pd_thumbnail
存储在数据库中。
答案 1 :(得分:0)
您正在使用此代码删除扩展程序 $ result_big = str_replace("。"。$ extension,"",$ image1);
我不知道你为什么那样做。无论如何,您可以通过在$ handle-> file_new_name_body = $ result_big;
之后添加以下行来添加回来$ handle-> file_new_name_ext = $ extension;