if (!
is_file($path)) { throw new DriverException('File does not exist locally and cannot be uploaded to the remote instance.'
);
} if (!
class_exists('ZipArchive'
)) { throw new DriverException('Could not compress file, PHP is compiled without zip support.'
);
} // Selenium only accepts uploads that are compressed as a Zip archive.
$tempFilename =
tempnam('', 'WebDriverZip'
);
$archive =
new \
ZipArchive();
$result =
$archive->
open($tempFilename, \ZipArchive::OVERWRITE
);
if (!
$result) { throw new DriverException('Zip archive could not be created. Error ' .
$result);
} $result =
$archive->
addFile($path,
basename($path));
if (!
$result) { throw new DriverException('File could not be added to zip archive.'
);
} $result =
$archive->
close();
if (!
$result) { throw new DriverException('Zip archive could not be closed.'
);
}