با سلام
من یه برنامه ای دارم مینویسم که یه فولدر میگیره و تمام فایلها و زیر فولدرهای اون رو به یه فایل زیپ تبدیل میکنه. این هم کدشه:
کد:
function creat_zip($source, $destination)     {         if (file_exists($source) === true)         {              $zip = new ZipArchive();             if ($zip->open($destination, ZIPARCHIVE::CREATE) === true)             {                  $source = realpath($source);                  if (is_dir($source) === true)                  {                       $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);                       foreach ($files as $file)                       {                            $file = realpath($file);                            if (is_dir($file) === true)                            {                                $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));                            }                            else if (is_file($file) === true)                            {                                $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));                            }                      }                 }                  else if (is_file($source) === true)                 {                      $zip->addFromString(basename($source), file_get_contents($source));                 }            }            return $zip->close();         }         return false;     }     creat_zip($path, $path . '/my_compressed.zip');     $file = $path . '/my_compressed.zip';       header("Expires: 0");       header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");       header("Cache-Control: no-store, no-cache, must-revalidate");       header("Cache-Control: post-check=0, pre-check=0", false);       header("Pragma: no-cache");       header("Content-type: application/pdf");       header('Content-length: '.filesize($file));       header('Content-disposition: attachment; filename='.basename($file));       readfile($file);
ولی یه مشکلی داره که وقتی فایل زیپ رو میسازه، داخل فایل زیپ به همون ترتیبی که بهش مسیر داده شده، از روت هارد فولدر تو فولدر میسازه و یکی یکی باید فولدرها باز بشه که به فولدر موردنظر که زیپ شده برسم (یعنی از روت هارد، مسیر رو نشون میده تو فایل زیپ). که این از نظر امنیت خیلی مشکل داره. چطور میشه این مشکل رو حل کرد به طوری که زمانی که فایل زیپ رو باز میکنم فقط فولدر مورد نظر که میخوام زیپ بشه رو نشون بده نه اینکه از ابتدای هارد مسیر رو یکی یکی نشون بده ؟؟