我正在使用一个函数来存储存储在目录中的原始图像的缩略图,现在我需要将该缩略图的文件路径保存在 db 中。
我怎样才能得到我的缩略图的路径?
<?php ob_start(); ?>
<?php
function make_thumb($src, $dest, $desired_width) {
/* read the source image */
$source_image = imagecreatefromjpeg($src);
$width = imagesx($source_image);
$height = imagesy($source_image);
/* find the "desired height" of this thumbnail, relative to the desired width */
$desired_height = floor($height * ($desired_width / $width));
/* create a new, "virtual" image */
$virtual_image = imagecreatetruecolor($desired_width, $desired_height);
/* copy source image at a resized size */
imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);
/* create the physical thumbnail image to its destination */
imagejpeg($virtual_image, $dest);
echo $thumb ."this is result";
$sql="INSERT INTO images thumb VALUES('$thumb')";
$result = mysql_query($sql) or die(mysql_error());
}
?>
<?php
//This is the directory where images will be saved
$target = "uploads/images/";
$target = $target . basename( $_FILES['photo']['name']);
//This gets all the other information from the form
$pic=($_FILES['photo']['name']);
// Connects to your Database
include('connect.php');
//Writes the information to the database
$sql="INSERT INTO images (name, alt)
VALUES('$pic','$_POST[altText]')";
$result = mysql_query($sql) or die(mysql_error());
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{
//Tells you if its all ok
echo "The file ". basename( $_FILES['photo']['name']). " has been uploaded, and your information has been added to the directory";
}
else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>
<?php
$src=$target;
$dest="uploads/thumbs/". basename( $_FILES[photo][name]);
$desired_width=160;
$quality=80;
make_thumb($src, $dest, $desired_width,$quality);
// here i need the code to save the file path of thumbnail
?>
<?php
//unset($_POST);
// 5. Close connection
mysql_close($connection);
header("Location: images.php");
?>
<?php ob_flush(); ?>
以上是我为此目的使用的代码。
在这方面的任何帮助将不胜感激