Using $ _SESSION for temporary image exchange

0

I am trying to create a simulator where the user can change the image, but when it closes the Browser, it returns the origin image, which is recorded in the BD.

I've been researching and I've seen that using $ _SESSION I could get the expected result, but I'm very lazy, and I'm not getting the result.

If friends can give me a glimpse of how I should proceed for such a task, I will 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>

I'm waiting for good tips, hugs to everyone.

    
asked by anonymous 18.05.2016 / 18:32

1 answer

0

You can try this:

session_cache_expire(180000);
session_start();

Or do via cookies:

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

and time to show:

$imgArray = $_COOKIE['logo_cookie'];
$img = imgArray["logo"]["tmp_name"];
    
18.05.2016 / 19:40