![]() Of course, you don’t need to implement these methods, but we’ve just refactored our code so that you don’t end up repeating the same code in other methods. It holds several methods, and each of them shows you a different way to create a zip file.Īpart from that, it provides two private methods, _load_zip_lib and _archieve_and_download, that are called from the rest of the methods. It’s a pretty standard controller file that you’re already familiar with. $this->_archieve_and_download('dir_images.zip') $this->zip->read_dir(FCPATH.'/uploads/images/') pass second argument as FALSE if want to ignore preceding directories ![]() $this->_archieve_and_download('images.zip') $this->zip->read_file(FCPATH.'/uploads/2.jpg') $this->zip->read_file(FCPATH.'/uploads/1.jpg') pass second argument as TRUE if want to preserve dir structure $this->zip->add_data('info/profile.txt', 'Web Developer') $this->zip->add_data('info/name.txt', 'Sajal Soni') $this->_archieve_and_download('my_info.zip') $this->zip->add_data('profile.txt', 'Web Developer') $this->zip->add_data('name.txt', 'Sajal Soni') $this->zip->archive(FCPATH.'/uploads/'.$filename) Private function _archieve_and_download($filename) Go ahead and create a file application/controllers/Zip.php with the following contents. #FILE UNZIPPER HOW TO#With everything in place, we’re ready to move on to our next section! How to Zip Files? application/libraries/Extractor.php: This file demonstrates the concept of a custom library in CodeIgniter.application/views/file_upload_result.php: It’s a view file that shows the result of a user-uploaded file basically it tells you if the file was successfully unzipped.application/views/file_upload_form.php : It’s a view file that holds pretty basic HTML file upload form code.application/controllers/Unzip.php: It’s a controller file that includes the code used to unzip a user-uploaded file.application/controllers/Zip.php: It’s a controller file that demonstrates various ways you could create a zip file.To achieve the desired functionality, the ZipArchive PHP extension comes to our rescue!īefore we go ahead and actually dive into the development stuff, I’ll list the files that we’re going to develop over the course of this tutorial: To demonstrate that, we’ll build a custom page that allows users to upload zip files that will be extracted on the server after successful file upload. ![]() The second half includes a discussion of how you can unzip the file. We’ll see how to create and save zip files on the server and how you can make them available for download to end users as well. #FILE UNZIPPER ZIP FILE#The first half of this tutorial explains different ways you can create a zip file using built-in CodeIgniter APIs. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |