Warning: Declaration of Bootstrap_Walker::start_lvl(&$output, $depth) should be compatible with Walker_Nav_Menu::start_lvl(&$output, $depth = 0, $args = NULL) in /home/itport/public_html/wp-content/themes/itport-v5.0/functions/bootstrap-walker.php on line 25

Warning: Declaration of Bootstrap_Walker::end_lvl(&$output, $depth) should be compatible with Walker_Nav_Menu::end_lvl(&$output, $depth = 0, $args = NULL) in /home/itport/public_html/wp-content/themes/itport-v5.0/functions/bootstrap-walker.php on line 42

Warning: Declaration of Bootstrap_Walker::start_el(&$output, $item, $depth, $args) should be compatible with Walker_Nav_Menu::start_el(&$output, $data_object, $depth = 0, $args = NULL, $current_object_id = 0) in /home/itport/public_html/wp-content/themes/itport-v5.0/functions/bootstrap-walker.php on line 57

Warning: Declaration of Bootstrap_Walker::end_el(&$output, $item, $depth, $args) should be compatible with Walker_Nav_Menu::end_el(&$output, $data_object, $depth = 0, $args = NULL) in /home/itport/public_html/wp-content/themes/itport-v5.0/functions/bootstrap-walker.php on line 108
آی تی پورت | ایجاد فایل ZIP با PHP
Warning: Use of undefined constant url - assumed 'url' (this will throw an Error in a future version of PHP) in /home/itport/public_html/wp-content/themes/itport-v5.0/header.php on line 56

Warning: Use of undefined constant title - assumed 'title' (this will throw an Error in a future version of PHP) in /home/itport/public_html/wp-content/themes/itport-v5.0/header.php on line 57
تجارت الکترونیکطراحی وب

ایجاد فایل ZIP با PHP

طراحی وب

این پست به شما کمک می کند برای ایجاد یک فایل ZIP با استفاده از PHP، با آرون چند خط از اسکریپت که سیستم تبدیل،  فایل های انتخاب شده را به فرمت ZIP  تبدیل می کند، به راحتی انجام دهید. این ویژگی بسیار مفید است برای پروژه های وب ، سایت تجارت الکترونیک مانند فروش فایل های PDF و تصاویر و اسناد ECT، با استفاده از این ویژگی شما می توانید فایل انتخابی خود را با فرمت فشرده دانلود کنید.

طراحی وب

             View Demo

HTML Code

<form name="zips" method="post">



<input type="checkbox" name="files[]" value="flowers.jpg" />

<img src="files/image.png" />

flowers.jpg



<input type="checkbox" name="files[]" value="fun.jpg" />

<img src="files/image.png" />

fun.jpg



<input type="checkbox" name="files[]" value="9lessons.docx" />

<img src="files/doc.png"   />

۹lessons.docx

........

<input type="submit" name="createpdf" value="Download as ZIP" /> 

<input type="reset" name="reset"  value="Reset" />

</form>

PHP Code

<?php

$error = ""; //error holder

if(isset($_POST['createpdf']))

{

$post = $_POST;

$file_folder = "files/"; // folder to load files

if(extension_loaded('zip'))

{

// Checking ZIP extension is available

if(isset($post['files']) and count($post['files']) > 0)

{

// Checking files are selected

$zip = new ZipArchive(); // Load zip library

$zip_name = time().".zip"; // Zip name

if($zip->open($zip_name, ZIPARCHIVE::CREATE)!==TRUE)

{

 // Opening zip file to load files

$error .= "* Sorry ZIP creation failed at this time";

}

foreach($post['files'] as $file)

{

$zip->addFile($file_folder.$file); // Adding files into zip

}

$zip->close();

if(file_exists($zip_name))

{

// push to download the zip

header('Content-type: application/zip');

header('Content-Disposition: attachment; filename="'.$zip_name.'"');

readfile($zip_name);

// remove zip file is exists in temp path

unlink($zip_name);

}



}

else

$error .= "* Please select file to zip ";

}

else

$error .= "* You dont have ZIP extension";

}

?>
گفتگو ها
    محمد

    مطلب مفیدی بود
    فقط لازم به ذکره که تابع پی اچ پی زیپ در نسخه های ۴ به بعد پی اچ پی عمل میکنه.

    سجاد!

    یکی از بهترین خوبی های ساخت زیپ این هست ک میشه با شبکه های اجتماعی ستش کرد و فایل های پیوستی کاربرا ب صورت زیپ ذخیره بشن
    این طوری در مصرف فضا تاثیر قابل مالاحضه ای دیده میشه…

    مریم

    بسیار عالی
    تشکر

    فایل ZipArchive را از کجا باید دانلود کرد