Adresten zip yükleme ve dizine çıkartma

 <?php
class urluploader {
                  private $filename; 
                  private $url; 
                  private $unzipdir;
       function __construct($fileurl,$dir=0)
              {
               if ($dir==0)
                      { $this->unzipdir=getcwd() . "/"; }
                      else {$this->unzipdir=$dir . "/";}
               $this->filename=$this->unzipdir . basename($fileurl);
                $this->url=$fileurl;
                }
       public function uploadFromUrl ()
               {
                 if(!filter_var($this->url, FILTER_VALIDATE_URL))
                     {die ("The provided url is invalid");}
                  $length=5120; 
                  $handle=fopen($this->url,'rb') or die ('gecersiz adres ');
                  $write=fopen ( $this->filename,'w');
                      while ( !feof($handle))
                        {
                           $buffer=fread ( $handle,$length );
                           fwrite ( $write,$buffer);
                         }
                  fclose ( $handle);
                  fclose ($write);
                  echo "<br>basarili:" . basename($this->filename) . "<br>" ;
                  return true;
               }
        public function unzip($newdir=false,$delete=false,$filename=false)
                {  if (!$filename){$filename=$this->filename;}
                          if(!$newdir){$newdir=$this->unzipdir;}
                     if (!file_exists($filename))
                           {die( 'bu dosya mevcut');}
                     if (class_exists('ZipArchive'))
	                  	{$zip = new ZipArchive;
			                  if($zip->open($filename) !== TRUE)
			                        {die('Unable to open the zip file');  }
		               	   $zip->extractTo($newdir) or die ('Unable to extract the file');
		                     echo "<br>Extracted the zip file<br>";
		                 	    $zip->close();
		                 }
		else
		{
			@shell_exec('unzip -d $newdir '. $this->filename);
			echo "<br>Unzipped the file using shell command<br>";
		}              
              If ($delete) {unlink($filename);
                 echo "<br>Deleting" . basename($filename);}
                return true;

                }
 }

 //örnek
 
        $upload= new urluploader("http://localhost/test.zip");//upload linki
       if($upload->uploadFromUrl())
       {$upload->unzip();}
       else {echo "basarisiz";}

 

Sizin Değerli Görüşlerinize İhtiyacımız Var.