peachpie
peachpie copied to clipboard
ZipArchive::getFromName returns empty data
Reading a zip file (specifically .xlsx) seems to return an empty string with the correct length instead of the actual data.
$zip = new ZipArchive;
$status = $zip -> open($filepath);
if ($status === true){
if ($zip -> locateName('xl/workbook.xml') !== false){
var_dump($zip->getFromName('xl/workbook.xml'));
//$XML = new SimpleXMLElement($zip->getFromName('xl/workbook.xml'));
}
}
Also, I tried using file_get_contents("zip://$filepath#xl/workbook.xml"); and got an error because it prepended the local path to the zip path.
System.IO.IOException: 'The filename, directory name, or volume label syntax is incorrect. : 'D:\Users\Bryan\Documents\Visual Studio 2019\Projects\horizon\horizon\horizon.Server\zip:\C:\Users\Bryan\AppData\Local\Temp\php_8d92f46c676f835-3887337.tmp#xl\workbook.xml''
we have tried the sample above and getting the correct content of 'xl/workbook.xml'
string(1727) "<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="x15 xr xr6 xr10 xr2" xmlns:x15="http://schemas.microsoft.com/office/spreadsheetml/2010/11/main" xmlns:xr="http://schemas.microsoft.com/office/spreadsheetml/2014/revision" xmlns:xr6="http://schemas.microsoft.com/office/spreadsheetml/2016/revision6" xmlns:xr10="http://schemas.microsoft.com/office/spreadsheetml/2016/revision10" xmlns:xr2="http://schemas.microsoft.com/office/spreadsheetml/2015/revision2"><fileVersion appName="xl" lastEdited="7" lowestEdited="7" rupBuild="24026"/><workbookPr defaultThemeVersion="166925"/><mc:AlternateContent xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"><mc:Choice Requires="x15"><x15ac:absPath url="D:\Downloads\" xmlns:x15ac="http://schemas.microsoft.com/office/spreadsheetml/2010/11/ac"/></mc:Choice></mc:AlternateContent><xr:revisionPtr revIDLastSave="0" documentId="8_{7ED8F5FC-EB36-4737-BF18-723E8353FBA2}" xr6:coauthVersionLast="47" xr6:coauthVersionMax="47" xr10:uidLastSave="{00000000-0000-0000-0000-000000000000}"/><bookViews><workbookView xWindow="330" yWindow="3150" windowWidth="24255" windowHeight="16890" xr2:uid="{37FC0E58-2B72-472D-BB89-99302975E33F}"/></bookViews><sheets><sheet name="Sheet1" sheetId="1" r:id="rId1"/></sheets><calcPr calcId="191029"/><extLst><ext uri="{140A7094-0E35-4892-8432-C4D2E57EDEB5}" xmlns:x15="http://schemas.microsoft.com/office/spreadsheetml/2010/11/main"><x15:workbookPr chartTrackingRefBase="1"/></ext></extLst></workbook>"
note: right, zip:// schema handler is not implemented
This is occurring after a file upload. I get an IO error but continuing the script returns an empty string with correct length. Seems like it can't read the file but it creates the string buffer.
System.IO.IOException: 'The process cannot access the file 'C:\Users\Bryan\AppData\Local\Temp\php_8d930092ec78703-A2809F.tmp' because it is being used by another process.'
This is an example upload code used assuming at least one file has been uploaded:
$zip = new ZipArchive;
$status = $zip -> open(array_values($_FILES)[0]["tmp_name"]);
if ($status === true){
if ($zip -> locateName('xl/workbook.xml') !== false){
var_dump($zip->getFromName('xl/workbook.xml'));
//$XML = new SimpleXMLElement($zip->getFromName('xl/workbook.xml'));
}
}
ok, I'll try the zip file from the $_FILES post variable; maybe we're incorrectly creating the temp files and keeping a lock on them.