gpt4 book ai didi

php - 将带有缩略图的图像上传到文件夹并添加到 Mysql 的路径

转载 作者:行者123 更新时间:2023-11-30 22:28:40 27 4
gpt4 key购买 nike

我愿意将带有自动缩略图的图像添加或更新到文件夹,并添加到 MySQL 数据库的路径。我用这个试过这段代码。我可以将图像上传到文件夹并将路径保存到数据库,但我无法生成缩略图,请帮助我解决这个问题。

<?php
ob_start();
include('include/connect.php');
if(isset($_GET['id']))
{
$qry = "SELECT * FROM tbl_emp where id=".$_GET['id'];
$result = mysql_query($qry);
$row = mysql_fetch_array($result);

if($_SERVER["REQUEST_METHOD"] == "POST")
{
$name = $_POST["name"];
IF($_FILES['file']['name']!='')
{
$file='uploads/'.$row['image'];
$thumbs='uploads/thumbs/'.$row['image'];
@unlink($file);
$tmp_name = $_FILES["file"]["tmp_name"];
$namefile = $_FILES["file"]["name"];
$ext = end(explode(".", $namefile));
$image_name=time().".".$ext;
$fileUpload = move_uploaded_file($tmp_name,"uploads/".$image_name);
$Uploadthumbs = move_uploaded_file($tmp_name,"uploads/thumbs/".$image_name);
}
else
{
$image_name=$row['image'];
}

$sqlAdd ="update tbl_emp set name='".$name."', image='".$image_name."' where id=".$_GET['id'];
mysql_query($sqlAdd);
header("Location:add.php?id=".@$_GET['id']."&msg=success");
exit;
}
}
else
{
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$name = $_POST["name"];
IF($_FILES['file']['name']!='')
{
$tmp_name = $_FILES["file"]["tmp_name"];
$namefile = $_FILES["file"]["name"];
$ext = end(explode(".", $namefile));
$image_name=time().".".$ext;

$fileUpload = move_uploaded_file($tmp_name,"uploads/".$image_name);
$Uploadthumbs = move_uploaded_file($tmp_name,"uploads/thumbs/".$image_name);
}
$sqlAdd = mysql_query("insert into tbl_emp(name,image) VALUES('$name','$image_name')");
header("Location:add.php?msg=success");
exit;
}
}
ob_end_flush();

if(isset($_GET['msg']))
{
?>
<div style="color:red;padding-bottom:10px;" class="form-message" align="center"><b>Task completd successfully.</b></div>
<?php
}
?>

最佳答案

生成缩略图的最简单方法是使用 class.upload.php 。有了它,您可以通过多种方式调整图像大小。

http://www.verot.net/php_class_upload.htm

关于php - 将带有缩略图的图像上传到文件夹并添加到 Mysql 的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34497619/

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