zip_entry_compressionmethod()函数是PHP中的一个内置函数,用于从zip存档项返回文件或目录的压缩方法。必须读取的zip条目资源作为参数发送给zip_entry_compressionmethod()函数,成功后返回压缩方法。
null
压缩方法有以下七种:
- 未压缩
- 缩小
- 瘪下来
- 减少(1至4)
- 令牌化
- 内爆
- BZIP2
压缩zip存档文件的默认压缩方法是deflated。
语法:
string zip_entry_compressionmethod( $zip_entry )
参数: 此函数接受单个参数 $zip_入口 .它是一个强制参数,用于指定zip条目资源。
返回值: 如果成功,它将返回指定zip存档项的文件或目录的压缩方法,否则将显示PHP警告。
错误和例外
- zip_entry_compressionmethod()仅在成功时返回文件或目录的压缩方法,否则返回PHP警告。
- 如果zip存档无效,zip_entry_compressionmethod()函数将返回一个ER_打开错误。
- 如果zip存档为空,zip_entry_compressionmethod()函数将返回一个ER_NOZIP错误。
下面的程序演示了PHP中的zip_entry_compressionmethod()函数:
项目1:
假设一篇zip文件文章。zip包含以下文件: 所容纳之物xlsx
<?php // Opening a zip archive $zip_handle = zip_open( "C:/xampp/htdocs/article.zip" ); // Reading a zip archive $zip_entry = zip_read( $zip_handle ); $file = zip_entry_name( $zip_entry ); // Checking the compression method $comp_type = zip_entry_compressionmethod( $zip_entry ); echo ( "File Name: " . $file . "=>" . $comp_type ); // Closing the zip archive zip_close( $zip_handle ); ?> |
输出:
File Name: article/content.xlsx => deflated
项目2:
假设一篇zip文件文章。zip包含以下文件: 艺术拉链 所容纳之物xlsx gfg。pdf 形象jpeg
<?php // Opening a zip archive $zip_handle = zip_open( "C:/xampp/htdocs/article.zip" ); if ( is_resource ( $zip_handle )) { // Reading a zip archive while ( $zip_entry = zip_read( $zip_handle )) { $file = zip_entry_name( $zip_entry ); // Checking the compression method $comp_type = zip_entry_compressionmethod( $zip_entry ); echo ( "File Name: " . $file . " => " . $comp_type . "<br>" ); } // Closing the zip archive zip_close( $zip_handle ); } else echo ( "Zip archive cannot be opened." ); ?> |
输出:
File Name: article/art.zip => stored File Name: article/content.xlsx => deflated File Name: article/gfg.pdf => deflated File Name: article/image.jpeg => deflated
相关文章:
参考: http://php.net/manual/en/function.zip-entry-compressionmethod.php
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END