单击添加到购物车时,如何自动将图像保存在网站内?
How can i automatically save the image inside a website when i click the add to cart?
如何自动保存这张披萨图片,并将其保存到我的本地文件夹?我可以轻松保存其他信息,但我遇到自动将图像本身保存在本地文件夹中的问题?
我正在从不同 table 获取其他数据,但我无法保存图像本身。我无意使用外键。
backend.php
if (isset($_POST['addcart'])) {
$con = connection();
$fetch = singleInfo();
$name = $fetch['name'];
$price = $fetch['price'];
$image = $fetch['image'];
$new_image = '../images/' . $image;
$stmt = $con->prepare("INSERT INTO `cart`(`name`, `price`,`image`) VALUES ('$name','$price','$new_image')");
$stmt->execute();
}
index.php
<?php
session_start();
require('../backend/clientbackend.php');
$fetch = singleInfo();
$current_price = $fetch['price'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./style/style.css">
<title>E-Commerce</title>
</head>
<body>
<nav>
<div class="left">
<h4 class="navbar-header"> <a href="../index.php">Branding</a> </h4>
<ul>
<li>Home</li>
<li>Shop</li>
<li>About</li>
</ul>
</div>
<div class="right">
<button class="loginButton">Login</button>
</div>
</nav>
<article>
<form method="post" class="product-description">
<div class="left">
<div class="left-title" name="name"> <?php echo $fetch['name']; ?> </div>
<div class="left-info">
<p class="left-description"> <?php echo $fetch['desc']; ?> </p>
<span class="price" name="price"> $ <strong> <?php echo $fetch['price']; ?></strong> </span>
</div>
<div class="left-increment">
<div class="addition">+</div>
<input type="number" class="current_value" value="1" min="1">
<div class="subtraction">-</div>
<button class="gotoCart" name="addcart" type="submit"> Add To Cart </button>
<a href="./cart.php">Go to cart</a>
</div>
</div>
<div class="right">
<div class="right-image">
<img name="image" src="<?php echo '../uploads/' . $fetch['image']; ?>" alt="">
</div>
</div>
</form>
</article>
<footer>
<div class="footer-container">
<div class="box1">
<h3>Ecommerce Branding</h3>
<span>School Activity</span>
</div>
<div class="box2">
<h3>Colegio De San Lorenzo
</h3>
<span>Congressional Ave, Project 8, Quezon City, Metro Manila</span>
</div>
<div class="box3">
<h3>Emman Cruz</h3>
<span> zurcemozz@gmail.com</span>
</div>
</div>
</footer>
<script>
const addBtn = document.querySelector('.addition');
const subBtn = document.querySelector('.subtraction');
let currentValue = document.querySelector('.current_value');
let stock = 1;
addBtn.addEventListener("click", function() {
stock = stock + 1
currentValue.value = stock;
console.log(currentValue.value);
})
subBtn.addEventListener("click", function() {
if (stock <= 0) {
stock = 0;
} else {
stock = stock - 1
currentValue.value = stock;
console.log(currentValue.value);
}
})
</script>
</body>
</html>
您可以将图像文件从“../uploads/”复制到“../images/”然后保存。
你可以用 copy function
来做到这一点
复制()示例:
<?php
$image = '../uploads/'.$fetch['image'];
$new_image= '../images/'.$fetch['image'];
if (!copy($image , $new_image)) {
echo "failed to copy $image ...\n";
}
?>
如何自动保存这张披萨图片,并将其保存到我的本地文件夹?我可以轻松保存其他信息,但我遇到自动将图像本身保存在本地文件夹中的问题?
我正在从不同 table 获取其他数据,但我无法保存图像本身。我无意使用外键。
backend.php
if (isset($_POST['addcart'])) {
$con = connection();
$fetch = singleInfo();
$name = $fetch['name'];
$price = $fetch['price'];
$image = $fetch['image'];
$new_image = '../images/' . $image;
$stmt = $con->prepare("INSERT INTO `cart`(`name`, `price`,`image`) VALUES ('$name','$price','$new_image')");
$stmt->execute();
}
index.php
<?php
session_start();
require('../backend/clientbackend.php');
$fetch = singleInfo();
$current_price = $fetch['price'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./style/style.css">
<title>E-Commerce</title>
</head>
<body>
<nav>
<div class="left">
<h4 class="navbar-header"> <a href="../index.php">Branding</a> </h4>
<ul>
<li>Home</li>
<li>Shop</li>
<li>About</li>
</ul>
</div>
<div class="right">
<button class="loginButton">Login</button>
</div>
</nav>
<article>
<form method="post" class="product-description">
<div class="left">
<div class="left-title" name="name"> <?php echo $fetch['name']; ?> </div>
<div class="left-info">
<p class="left-description"> <?php echo $fetch['desc']; ?> </p>
<span class="price" name="price"> $ <strong> <?php echo $fetch['price']; ?></strong> </span>
</div>
<div class="left-increment">
<div class="addition">+</div>
<input type="number" class="current_value" value="1" min="1">
<div class="subtraction">-</div>
<button class="gotoCart" name="addcart" type="submit"> Add To Cart </button>
<a href="./cart.php">Go to cart</a>
</div>
</div>
<div class="right">
<div class="right-image">
<img name="image" src="<?php echo '../uploads/' . $fetch['image']; ?>" alt="">
</div>
</div>
</form>
</article>
<footer>
<div class="footer-container">
<div class="box1">
<h3>Ecommerce Branding</h3>
<span>School Activity</span>
</div>
<div class="box2">
<h3>Colegio De San Lorenzo
</h3>
<span>Congressional Ave, Project 8, Quezon City, Metro Manila</span>
</div>
<div class="box3">
<h3>Emman Cruz</h3>
<span> zurcemozz@gmail.com</span>
</div>
</div>
</footer>
<script>
const addBtn = document.querySelector('.addition');
const subBtn = document.querySelector('.subtraction');
let currentValue = document.querySelector('.current_value');
let stock = 1;
addBtn.addEventListener("click", function() {
stock = stock + 1
currentValue.value = stock;
console.log(currentValue.value);
})
subBtn.addEventListener("click", function() {
if (stock <= 0) {
stock = 0;
} else {
stock = stock - 1
currentValue.value = stock;
console.log(currentValue.value);
}
})
</script>
</body>
</html>
您可以将图像文件从“../uploads/”复制到“../images/”然后保存。 你可以用 copy function
来做到这一点复制()示例:
<?php
$image = '../uploads/'.$fetch['image'];
$new_image= '../images/'.$fetch['image'];
if (!copy($image , $new_image)) {
echo "failed to copy $image ...\n";
}
?>