Jump to content

problem with extract rar


yosii

Recommended Posts

this is my code


<?php


  $zip = new ZipArchive();
  
  $zip = new ZipArchive();
if($zip->open("C.zip",ZIPARCHIVE::CREATE)===TRUE)
{
$dir = scandir('test/');
$new_dir='test/';
$num=count($dir);
for($k=0; $k<=$num; $k++)
{
	if (@$dir[$k]!="." && @$dir[$k]!="" && @$dir[$k]!=".." && @$dir[$k]!="Thumbs.db")
	{	$new_file=$new_dir.$dir[$k]; echo $new_file.'<BR>';
		$zip->addFile($new_file);
	}
}




   

   $zip->close();
$file = "C.zip";
header ("Content-Type: application/octet-stream");
header ("Accept-Ranges: bytes");
header ("Content-Length: ".filesize($file));
header ("Content-Disposition: attachment; filename=".$file);  
readfile($file);
}
  ?>

what i want is to download folder in rar and becuase of that i run FOR that read and add all my file to the function

so....

it is download good  and if i enter to the RAR file i see the file that in there...GOOD

but when i tried to extract the file i get problem in RAR

The archive is either in unknown format or damaged

why????

if I do this code diffrend and choose file by file like

<?php


  $zip = new ZipArchive();
  
  $zip = new ZipArchive();
if($zip->open("S.zip",ZIPARCHIVE::CREATE)===TRUE)
{
$zip->addFile('test/1.GIF');
$zip->addFile('test/2.GIF');	
$zip->addFile('test/3.GIF');


   

   $zip->close();
$file = "S.zip";
header ("Content-Type: application/octet-stream");
header ("Accept-Ranges: bytes");
header ("Content-Length: ".filesize($file));
header ("Content-Disposition: attachment; filename=".$file);  
readfile($file);
}
  ?>

this work good

that the problem in the FOR that run on all the folder that make problem when i extract the files..

thank

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.