简体   繁体   English

单击添加到购物车时,如何自动将图像保存在网站内?

[英]How can i automatically save the image inside a website when i click the add to cart?

how can I automatically save this pizza image, and save it to my local folder?我怎样才能自动保存这个披萨图像,并将它保存到我的本地文件夹? I can easily save the other information, but I'm encountering automatically saving the image itself in a local folder?我可以轻松保存其他信息,但我遇到自动将图像本身保存在本地文件夹中的情况?

I'm fetching the other data from different table, but the I can't save the image itself.我正在从不同的表中获取其他数据,但我无法保存图像本身。 I'm have no intention of using foreign key for no.我无意使用外键。

backend.php后端.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 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>

样本图像

you can copy the image file from '../uploads/' to '../images/' and then you save it.您可以将图像文件从“../uploads/”复制到“../images/”,然后保存。 you can do this with copy function您可以使用副本function 执行此操作

copy documentations复印文件

copy() example:复制()示例:

<?php
$image = '../uploads/'.$fetch['image'];
$new_image= '../images/'.$fetch['image'];

if (!copy($image , $new_image)) {
    echo "failed to copy $image ...\n";
}
?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 每次单击添加到购物车按钮时,如何在会话数组中添加值? - How can I add value in a session array every time I click add to cart button? 如何在简码内添加图片 - How can I add an image inside a shortcode 如果我单击已在购物车中的产品的“添加到购物车”按钮,如何重定向到购物车页面 - How do I redirect to the cart page if I click on the 'Add to cart' button for a product that's already in cart 我想使用laravel单击“添加到购物车”按钮时,将商品显示在购物车中吗? - I Want to show products items into shopping cart when i click add to cart button using laravel? 我如何登录网站并保存cookie? - How can i login to a website and save cookies? 如何保存“图像点击”值,以便我可以继续在我的 PHP 程序中使用该值? - How can I save an "Image Click" value so that I can continue working with this value in my PHP program? 将产品成功添加到购物车后,如何添加ajax通知 - how can I add ajax notice when the product was successfully added to cart 如果缺少图像文件名,如何使用 php 自动添加图像“alt”属性? - How can I automatically add the image "alt" attribute using image filename if it is missing, using php? 当我点击添加到购物车按钮时会发生什么我在 laravel 中遇到了一些错误? - what happens when i click add to cart button i am facing some error in laravel? 我如何用图标替换“添加到购物车”文本(添加到购物车按钮woocommerce) - How can i replace text “Add to cart” with an icon (Add to cart button woocommerce)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM