Using $_SESSION for temporary image exchange

Asked

Viewed 70 times

0

I’m trying to create a simulator where the user can change the image, but when he closes the Browser, returns the source image, which is recorded in the BD.

I have been researching and I saw that using $_SESSION I could get the expected result, but I am very lay, and I am not getting the result.

If friends can shed some light on how I should proceed to such a task, I would be most grateful.

Below the code I’m trying to use...

    <?php
    // Start the session
    session_start();
    ?>
    <!DOCTYPE html>
    <html>
    <body>

    <?php
    // Set session variables
    $_SESSION["logo"] = "8081.png";
    ?>

    </body>
    </html>
    <img width="200" src="img/<?php echo $_SESSION['logo']; ?>" />

    <?php 
    $img = $_SESSION["logo"]["tmp_name"];
    $logo=$_FILES["logo"]["name"]; 
    copy($img,$logo);
    ?>

    <form method="get">
    <input type="file" accept="image/*" name="$_SESSION['logo']"><br>
    <input type="submit" name="logo" value="Atualizar">
    </form>

Waiting for good tips, hugs to everyone.

1 answer

0

You can try this way:

session_cache_expire(180000);
session_start();

Or do through cookies:

setcookie('logo_cookie', $_SESSION['logo'], time() + 60 * 60 * 24);

and when it’s time to show:

$imgArray = $_COOKIE['logo_cookie'];
$img = imgArray["logo"]["tmp_name"];
  • Hello Anderson, if you enter the address (http://www.efacil.com), you will have an idea of what I need. I’ll explain in more detail, okay? Hugs.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.