How can i get the zipped file folder name after unzipping in php.
$zip = new \ZipArchive();
$zip->open(storage_path('app/'.$request->vrfile));
$zip->extractTo(public_path('tour_videos/videos/'.str_slug($company)));
$zip->close();
unlink(storage_path('app/'.$request->vrfile));
Zipped file is called Kigali Home Web Tour
And After Unzipping the file the folder name is Web Tours
How can i get the folder name after extracting zipped files??
$name = $zip->open(storage_path('app/'.$request->vrfile));
$name will give you an absolute path as well as the name of your folder.
Related
After moving a website from one server to another, both running IIS, when a zip file creation script is called the file created has some random characters at the end, ex. what should be 'test.zip' is converted to 'test.zip08c1b35d' giving error when trying to download them.
I've discovered that it only happens inside the website path, if I create a symbolic link inside the website path with the same name, pointing to a folder outside the website path the zip file is created with the correct name. Any other folder within the website path the name is changed.
The zip file format is correct as if I delete the characters and leave the name ending '.zip' the file opens fine.
The code used is:
$dir ='../mylims/test/';
$destination = $dir.'test.zip';
$zip = new ZipArchive();
if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
echo "Error";
}
$zip->addFile('./test/testfile.txt','testfile.txt');
$zip->close();
Any suggestions what to look? Tks
My file structure in zip is
lib
css
js
app1
app2
index.php
All the above files and folders are in test.zip
i want to extract this test.zip using php
$zip = new ZipArchive;
$res = $zip->open("test.zip");
if ($res === TRUE)
{
$zip->extractTo('path');
$zip->close();
}
if lib folder is already exist in the directory where we are unzipping then except lib(folder) all other files and folders should get override.
how to solve this.
http://php.net/manual/en/ziparchive.open.php , on open, pass in the over write flag.
I have a website with the following path for images: domain.com/images
I am using a PHP script in the back-end to upload images to that folder BUT the page that lets me upload images to that path above is located at domain.com/administration/upload.php.
So now when I am using a script to write to domain.com/images this is what I am using:
$newname="/images/".$image_name;
For some reason it won't write to that folder and I get no errors and here's the link from where I got the script:
http://www.reconn.us/content/view/30/51/
What do I have to do to make it write to that domain.com/images path from domain.com/administration/upload.php?
You have to distinguish virtual server path from filesystem path.
There are no /images/ directory on your disk
but something like /home/www/user/public_html/images/
so, change your code to
$newname = $_SERVER['DOCUMENT_ROOT']."/images/".$image_name;
and it should be okay
You can try this for the exact path to folder
/* $_SERVER['DOCUMENT_ROOT'] will point to your root folder( www ) and after that your website folder name and them images folder name */
$newname = $_SERVER['DOCUMENT_ROOT']."/folder name/".$image_name;
Im moving un-zipped files to a server directory /zip/file.unzipped.png
now i need to take that file and zip it.
Is it possible to do that or a need the zip archive as codeigniter guide says?
How can i do that?
Is what you're looking for just a straight download, and not saving the archive on disk before download?
If this is the case you can do what #zer02 suggested, but remove the archive step.
$name = 'mydata1.txt';
$data = 'A Data String!';
$this->zip->add_data($name, $data);
// Write the zip file to a folder on your server. Name it "my_backup.zip"
$this->zip->archive('/path/to/directory/my_backup.zip');
// Download the file to your desktop. Name it "my_backup.zip"
$this->zip->download('my_backup.zip');
The zip library should gather up all the data you've added to the zip cache in memory, and create a file to download dynamically.
Please read the user manual: http://codeigniter.com/user_guide/libraries/zip.html
There are two functions that jump out me for your use case:
$this->zip->read_file()
Permits you to compress a file that already exists somewhere on your
server. Supply a file path and the zip class will read it and add it
to the archive:
$this->zip->read_dir()
Permits you to compress a folder (and its contents) that already
exists somewhere on your server. Supply a file path to the directory
and the zip class will recursively read it and recreate it as a Zip
archive. All files contained within the supplied path will be encoded,
as will any sub-folders contained within it.
$name = 'mydata1.txt';
$data = 'A Data String!';
$this->zip->add_data($name, $data);
// Write the zip file to a folder on your server. Name it "my_backup.zip"
$this->zip->archive('/path/to/directory/my_backup.zip');
// Download the file to your desktop. Name it "my_backup.zip"
$this->zip->download('my_backup.zip');
Zip Lib CI
I found this script on stackoverflow but am having an issue. The zip is being created with the file I am telling it to but it's also zipping the lower directories to that file. The zipped file contains: \uploads\1\assets\2\ai\filename.ai
$zip = new ZipArchive();
$zip->open('uploads/1/assets/2/ai/filename.zip', ZIPARCHIVE::CREATE);
$zip->addFile('uploads/1/assets/2/ai/filename.ai');
$zip->close();
$zip->addFile('uploads/1/assets/2/ai/filename.ai', 'filename.ai');
The second parameter is the localname:
If supplied, this is the local name inside the ZIP archive that will
override the filename.
If you leave off the directory path, it will not be included in the zip file.