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"
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 ?
– Samuel Machado
@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
– cHida
Thank you very much for your support :)
– Samuel Machado