I am new in codeigniter, even in PHP.
I want to upload a zipped folder which may contain the module of CMS including sub directories .On other hand I have to unzip the folder at server side.
Is there any way to accomplish this task?
I've ever tried to upload & unzip the uploaded zip file (that contain XML file), unzip it & extract the XML data on the server side.
I used CodeIgniter-Unzip library to unzip the uploaded zip file, it's easy to use. Here is the source
CodeIgniter-Unzip
Hope it helps :)
Related
I have a Symfony 2 project with an upload folder (uploads works well). I'm creating a ZIP file after the upload which I put inside the same folder as the uploaded file (so the archive is created from the PHP script).
But i cannot extract the archive afterwards under MAC OS. The error is the following ("100" beeing a folder inside the upload folder):
What does that mean in MAC OS ? I suspect this is a directory permission issue. If i move and try to extract the ZIP on my Desktop it does not work either. I don't know in which direction to look. I've noticed if i try to do the same thing on another PHP project on which i DIDN't mess with the permissions required when installing symfony, the script and ZIP extraction works...
Updates :
Folder/files permissions :
Sudo unzip result :
Any ideas ? Thanks in advance,
Got it working ! NEVER trim() a ZIP file contents before saving it somewhere on your server. It seems to corrupt the archive.
I cannot believe this hasn't been asked before, but I cannot find the answer on stackoverflow, please redirect me if this is a duplicate and I'm too retarded to find it.
I am creating a script that will download a kmz file from my custom google map, then will unzip it, read the xml and create a web page that lists all my markers. But I don't have access to the servers to create a writable folder so where can I download the kmz file to then unzip it?
Tried the temp folder (/var/tmp) and it seems to download the file, but I cannot work on the file afterwards or extract it, probably because the file gets deleted right after I call fclose, after downloading, as it doesn't exist anymore if I scan the directory.
UPDATE:
To answer question, the file is immediately deleted because it is a shared server and there are tons of session files in that folder that are created by all the visitors of each websites
I have 16631 files hosted in a webserver, 2719 of them are text files that contains a list of specific files located on the server.
Using PHP, is possible to create a ZIP for each text file?
could be the text file name as ZIP file name?
I want to keep the same directory structure in the ZIP file.
Thanks in advance.
Taking the suggestion from Jeff Hines, you could use the ZipArchive class to create the zip.
In Pseudo code
Get List of Text Files in your folder
Read Text file and get list of files to add to zip
Using ZipArchive add each listed file to your new zip file.
Write flag to specify you've done this file.
You might need to run it on 10 files at a time since it may time out.
I'm working on a php script packaging some files (a setup.exe and a licence.txt which is created direct in php for the user). We don't want that the user has to unzip it and start setup.exe.
On the computer we solved that by using selfextracting zips with:
zip is called setup.exe
zip has icon of the application
destination of extraction is temporary folder
extracting process is hidden
So if the user click on setup.exe he don't know that this setup.exe is a zip at the end.
But is that also possible on the server in the php script?
i tried the normal ziparchive object and pclzip and i can create the zip with these libraries. But i cannot change the parameters above...
Can anyone tell me if there's a solution for this?
Use PHP:exec to run an external application that compress and compile your exec file, with your stuff inside as you need.
PHP don't have built-in function to compress and compile and executable file.
Is there a way to add files to a zip file from another server with php's zip extension? ie.
addFile(array('localfile.txt,'http://www.domain.com/remotefile.txt'))
//(that obviously does not work)
I suppose I can download the files to a temporal folder and then add them to the zip file, but I was looking for a more automated solution or a function already made
use file_get_contents() and ZipArchive::addFromString()
$zipArchiveInstance->addFromString($filename, file_get_contents($mediaUrl));
This writes the contents fetched remotely straight into your php object (no need to write/read temp file)
It's not hard to read remote files in PHP.
file_get_contents("http://example.com/remote.txt");
Or to copy them locally:
copy("http://example.com/remote.txt", "/tmp/local.txt");
Whichever way you do it, the contents are going to have to be transferred to a local temp folder or memory before you can do anything with them.
Fetch them with cURL, add them from TEMP directory.