Jump to content
php.lv forumi

zips


Genesis

Recommended Posts

Sveiki,

gribējās zināt no pieredzējušākiem lietotājiem par to no kuras php versijas dabojas zipa funkcijas. Nu ir tā ka uzliku lapu uz servera kurai ir php 5.04 un principā nestrādā - izsaucu funkciju un viss apstājas... pat erorus neuzmet. Tāpēc kur ir vaina - kodā vai arī php versijā (ieks php info rādija ka zips ir un ir enablots).


if (isset($_POST['dw']))
{	
	$gallery=$_POST['id'];						
	$results = mysql_fetch_assoc(mysql_query("SELECT * FROM gallerys WHERE path='{$gallery}'"));
	$gallery_name=$results['gallery_name'];		

	$result = mysql_query("SELECT * FROM pictures WHERE galleryID='{$gallery}'");
	$masivs=array();
	while($row=mysql_fetch_assoc($result))
		{      
			$masivs[] = 'Gallerys/'.$gallery.'/'.$row['picture_name'];
		}
	$url=curPageURL();		
	$gallery_name = zip_filename($gallery_name);		
	if (create_zip($masivs, 'Gallerys/'.$gallery.'/'.$gallery_name.'.zip', true))
		{
			$file='Gallerys/'.$gallery.'/'.$gallery_name.'.zip';
			header('Content-Description: File Transfer');
			header('Content-Type: application/octet-stream');
			header('Content-Disposition: attachment; filename='.basename($file));
			header('Content-Transfer-Encoding: binary');
			header('Expires: 0');
			header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
			header('Pragma: public');
			header('Content-Length: ' . filesize($file));
			ob_clean();
			flush();
			readfile($file);
			$url=curPageURL();				
			redirect_to($url);
		}
	else 
		{
			redirect_to("index.php");
		}
}

function create_zip($files,$destination,$overwrite) 
{      	 
        if(file_exists($destination) && !$overwrite)
		{
			return false; 
		}
        $valid_files = array();
        if(is_array($files)) 
		{
			 foreach($files as $file) 
				{
					if(file_exists($file)) 
						{
							$valid_files[] = $file;
						}
				}
		}
      if(count($valid_files)) 
		{
		$zip = new ZipArchive();  
		if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) 
			{ 
				return false;
			}
     foreach($valid_files as $file) 
		{
			$zip->addFile($file,basename($file));
		}       
     $zip->close();
     return file_exists($destination); 
		}
     else  
	  {
		return false;
	  }
     }

Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...