Is it possible to store the tmp_name of a file in cookies?

2

I have the following code

$allowed = array('png', 'jpg', 'gif','zip');

    if(isset($_FILES['upl']) && $_FILES['upl']['error'] == 0){

        $extension = pathinfo($_FILES['upl']['name'], PATHINFO_EXTENSION);

        if(!in_array(strtolower($extension), $allowed)){
            echo '{"status":"error"}';
            exit;
        }
        else{

            $nomesImagens = (isset($_COOKIE['nomesImagens'])) ? $_COOKIE['nomesImagens'] : '';

            if (empty($nomesImagens)) {
                setcookie("nomesImagens", $_FILES['upl']['name'], time()+300, "/");
            }
            else{
                $novoNome = $_COOKIE['nomesImagens'].",".$nomesImagens;
                setcookie("nomesImagens", $novoNome, time()+300, "/");
            }


            $tmpImagens = (isset($_COOKIE['tmpImagens'])) ? $_COOKIE['tmpImagens'] : '';

            if (empty($tmpImagens)) {
                setcookie("tmpImagens", $_FILES['upl']['tmp_name'], time()+300, "/");
            }
            else{
                $novoNome = $_COOKIE['tmpImagens'].",".$tmpImagens;
                setcookie("tmpImagens", $novoNome, time()+300, "/");
            }


        }

    }

    echo '{"status":"error"}';
    exit;

For each selected image it preloads the image and stores the tmp_name and name of the image in cookies through an ajax request, however at the time of inserting the whole form, the input files are added so I have to insert the cookies which I have already recorded, it inserts into the bank but does not allocate the images, is it possible to do this with temporary files?

    
asked by anonymous 14.12.2016 / 17:30

1 answer

2

One suggestion is to upload the image to a temporary folder with the name of the image.

When you are actually inserting into the database, look in the temporary folder for the image because you have a session or cookie name. Make a copy to the correct folder and then delete the image from the temporary folder.

Workable, but it works.

    
14.12.2016 / 17:51