Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
validateFileIsZip example
private
const
HEADER_SIGNATURE = '504b0304';
public
static
function
openZip
(
string
$filename
)
: \ZipArchive
{
$stream
=
new
\
ZipArchive
(
)
;
if
(
!
file_exists
(
$filename
)
)
{
throw
PluginException::
cannotExtractNoSuchFile
(
$filename
)
;
}
if
(
!self::
validateFileIsZip
(
$filename
)
)
{
throw
PluginException::
cannotExtractInvalidZipFile
(
$filename
)
;
}
if
(
(
$retVal
=
$stream
->
open
(
$filename
)
)
!== true
)
{
throw
PluginException::
cannotExtractZipOpenError
(
self::
getErrorMessage
(
$retVal
,
$filename
)
)
;
}
return
$stream
;
}
private
static
function
getErrorMessage
(
int
$retVal
, string
$file
)
: string
{