tmp_name of files inside a zip folder

Asked

Viewed 159 times

0

I am doing with php code that in which I upload a zip file and it returns me the list of the names of the files that is inside the zip file. But I need it to be returned to the zip folder itself, and not just the name, ie when I give the var_dump(), he shall return to me the ['tmp_name'], just as it is done with zip folder, but this time from each file. Can anyone help me? I’m starting in PHP.

HTML:

<DOCTYPE html>
<html>
    <head>
        <title>CIC Project</title>
    </head>
    <body>
        <h1>Test File .zip</h1>
        <form method="POST" action="testeZip.php" enctype="multipart/form-data">
            <input type="file" accept=".zip" id="arquivo" name="arquivo"><br>
            <button type="submit" id="buttonSubmit">POST</button>
        </form>
    </body>
</html>

PHP:

<?php

    if(isset($_POST)){
        $today = date("mY");
        $arquivoFile = $_FILES['arquivo'];
        var_dump($arquivoFile);
        $arquivo = zip_open($arquivoFile['tmp_name']);

        if($arquivo){
            while($lista_arquivos = zip_read($arquivo)){
                $newArchieves = $lista_arquivos.$_FILES['arquivo']['tmp_name'];
                echo "- Nome do Arquivo: ".zip_entry_name($lista_arquivos)."<br>";
                var_dump($newArchieves);
            }
            zip_close($arquivo);
        }

    }
?>

Current Result:

array(5) { ["name"]=> string(26) "CONTASCEMIG_PBH_012019.zip" ["type"]=> string(28) "application/x-zip-compressed" ["tmp_name"]=> string(23) "C:\xampp\tmp\phpF60.tmp" ["error"]=> int(0) ["size"]=> int(5738) } - Nome do Arquivo: 266774672_PRODABEL_17022019_BT.xml
string(37) "Resource id #3C:\xampp\tmp\phpF60.tmp" - Nome do Arquivo: 266774672_PRODABEL_17022019_MT.xml
string(37) "Resource id #4C:\xampp\tmp\phpF60.tmp" - Nome do Arquivo: 356438293_BELOTUR_17022019_BT.xml
string(37) "Resource id #5C:\xampp\tmp\phpF60.tmp" - Nome do Arquivo: 849202935_SECFAZENDA_17022019_MT.xml
string(37) "Resource id #6C:\xampp\tmp\phpF60.tmp" - Nome do Arquivo: 938478493_LIMPEZAPUB_17022019_FR.xml
string(37) "Resource id #7C:\xampp\tmp\phpF60.tmp"

1 answer

1


the tmp_name is just the temporary path where the file gets saved before you move it to the folder you want, it is not the original is only temporary. If you want the name of the zip file you sent it is in the parameter name in the case $arquivoFile['name']

To move the tmp file you are sending to another folder, you must use the move_uploaded_file more info in PHP doc http://php.net/manual/en/function.move-uploaded-file.php

  • Thank you for the clear answer, cHida, but I would like to know even is the name of the files inside the . zip, and how to get to them, for example, *do not want to download , but suppose I want to download a certain file inside the zip folder... in this case I would need to get to the right file, right? how could I get there ?

  • @Samuelmachado dude, you have to open the zip by PHP extract and grab the file you want. Just look at the PHP documentation for Zip and move the file with move_uploaded_file to the folder you want. This is the documentation you need http://php.net/manual/en/class.ziparchive.php

  • Thank you very much for your support :)

Browser other questions tagged

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