Hi I want to extract a KMZ file that has an Images folder with some images and a kml file
Other questions here just have the kml file but mine has a images folder too!
how can I extract it?
I tried this but it didn't work
$data = file_get_contents("test/test.kmz"); // url of the KMZ file
file_put_contents("/test/kmz_temp",$data);
ob_start();
passthru('unzip -p /test/kmz_temp');
$xml_data = ob_get_clean();
header("Content-type: text/xml");
dd($xml_data);
and also this
$zip = new ZipArchive();
$zip->open('test/test.kmz');
$zip->extractTo('/test/public');
$zip->close();**strong text**
I found my solution
if you change the format of the file (while moving it to your folder) to zip it will extract it
Related
i want to combined multi image/pdf to one single pdf file in laravel. i use Imagick packages, here is my code:
$document1 = DocCust::latest('created_at')->where('cus_id',$id)->where('type','1')->first();
$document2 = DocCust::latest('created_at')->where('cus_id',$id)->where('type','2')->first();
$file1= public_path().'/documents/user_doc/'.$id.'/'.$document1->doc_pdf;
$file2= public_path().'/documents/user_doc/'.$id.'/'.$document2->doc_pdf;
$path = public_path().'/documents/user_doc/'.$id;
$images = array($file1, $file2);
$pdf = new Imagick($images);
$pdf->setImageFormat('pdf');
$pdf->writeImages('combined.pdf', true);
its works perfectly, but the new file pdf is saved to 'public' folder. i want to save the new pdf into folder based on their id.
public/documents/user_doc/'.$id.'
i tried to change this code with path, but i get error failed to open stream not found file etc..
$pdf->writeImages($path.'/'.'combined.pdf', true);
I am trying to read contents of zipped file as
$subda=file_get_contents('http://www.yifysubtitles.com/subtitle/thewilbyconspiracy1975dvdripxvid-english-128250.zip');
And trying to upload at my online server as below
$this->load->library('zip');
$data = $subda;
$name = 'myfile.srt';
$this->zip->add_data($name, $data);
$this->zip->archive('assets/subtitles/myzipfile.zip');
But when I check this uploaded file at my server it does not compressed properly.
it does not contain any data.
when I echo $subda it give results like.
Where I am wrong...
through file_get_contents I am already getting contents of zip file.
You cannot do:
$subda=file_get_contents('http://www.yifysubtitles.com/subtitle/thewilbyconspiracy1975dvdripxvid-english-128250.zip');
This will just load the ZIP content into the string rather than uncompressed.
See this on how you can read using a lib in php:
Best way to read zip file in PHP
I'm trying to generate OpenDocument Streadsheets using PHP.
This is my code:
$content_xml = '<?xml version="1.0" encoding="UTF-8"?><office:document-content ...';
$file = 'spreadsheet.ods'; // this one is beeing generated. It is not existent yet...
$zipfile = 'container.zip'; // this one already exists. It's in the same directory
// this script is in. I created the container.zip by unziping a usual .ods file,
// removing the content.xml and ziping again
$handle1 = fopen($zipfile, "r");
$handle2 = fopen($file, "w");
// writing the content of the `container.zip` to the `spreadsheet.ods`
fwrite($handle2, fread($handle1, filesize($zipfile)));
fclose($handle1);
fclose($handle2);
$zip = new ZipArchive();
$zip->open($file, ZIPARCHIVE::CREATE);
// adding the xml string to the zip file
$zip->addFromString('content.xml',$content_xml);
$zip->close();
header('Content-disposition: attachment; filename="'.$file.'"');
header('Content-Type: application/vnd.oasis.opendocument.spreadsheet');
header('Content-Length: ' . filesize($file));
readfile($file);
unlink($file);
If I open the generated file with OpenOffice - everything looks fine. But MS Excel for some reason is not able to open the file. I think the XML string in $content_xml is corrupt. I don't want to bother anybody with that string - it is huge! I got it from a simple ods spreadsheet. I just edited the <office:body>...</office:body> part.
I wondering whether this is a good way to generate spreadsheets. Does anybody know a tutorial for this task:
do all that zip stuff
structure of a simple content.xml in an ods file
Regarding "1. do all that zip stuff":
what I do here is generating the content.xml and adding it to the root of the .ods structure
Configurations2 // Folder
META-INF // Folder
Thumbnails // Folder
meta.xml
mimetype
settings.xml
styles.xml
By doing
$zip->addFromString('content.xml',$content_xml);
But how can I add a file NOT to the root of the structure but (let' say) to Configurations2/images/Bitmamps?
You can find full details of the OpenOffice (OASIS) format on the OASIS technical pages while The Open Office website provides DTDs and some tutorials
I have a gzip file. Into this file I have many csv files. I want to read only one of these files that are contained into the gzip folder. The name of the gzip folder that I want to read is 'com.instore'. And the name of the csv file is 'second'.
I use the gzopen() to read the gzip folder. But now I don't know how to read the csv file contained inside.
So, how can I do this?
Do I have to close with the gzclose()?
The gzip is into a server directory. How can I reach it?
When you gzopen you dont uncompress it. you just creates a file pointer to it.
<?php
// get contents of a gz-file into a string
$filename = "/usr/local/something.txt.gz";
$zd = gzopen($filename, "r");
$contents = gzread($zd, 10000);
gzclose($zd);
?>
while $contents is your csv file as a string.
more info # http://www.php.net/manual/en/function.gzread.php
You can extract the gzip file using this:
How can I extract or uncompress gzip file using php?
and than using this:
How to import csv file in PHP?
populate the database.
I created xml file in php. This file is successfully saved in my server directory.
Now, I want to download this file only through php, not javascript.
How can I save this file?
Try file_get_contents() and file_put_contents().
<?PHP
$xml = file_get_contents("http://yoursite.com/yourxml.xml"); // your file is in the string "$xml" now.
file_put_contents("/path/to/file/yourxml.xml", $xml); // now your xml file is saved.
?>