Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP逐个解压文件和解压缩文件_Php_Zip - Fatal编程技术网

PHP逐个解压文件和解压缩文件

PHP逐个解压文件和解压缩文件,php,zip,Php,Zip,我想创建一个PHP代码来解压缩一个文件,然后将其解压缩到一个文件夹中。我知道要解压缩zip中的所有文件,但是,我想一个接一个地解压缩,因为我想检查每个文件是否需要低于1MB 这是我的密码: $zip = new ZipArchive(); for ($i=0; $i<$zip->numFiles;$i++) { $current = $zip->statIndex($i); if($current["size"] > (1*102

我想创建一个PHP代码来解压缩一个文件,然后将其解压缩到一个文件夹中。我知道要解压缩zip中的所有文件,但是,我想一个接一个地解压缩,因为我想检查每个文件是否需要低于1MB

这是我的密码:

$zip = new ZipArchive();
for ($i=0; $i<$zip->numFiles;$i++) 
    {
        $current = $zip->statIndex($i);
        if($current["size"] > (1*1024*1024))
        {
            printf("%s (size: %d bytes) is too big, failed to upload this photo<br>", $current["name"], $current["size"]);
        }
        else
        {
            $location = 'picture/'.$current['name'];
            if(move_uploaded_file($current['name'], $location))
                printf("%s successfully uploaded<br>", $current["name"]);
            else
                printf("Failed <br />");
        }
    }
$zip=new ZipArchive();
对于($i=0;$inumFiles;$i++)
{
$current=$zip->statIndex($i);
如果($current[“size”]>(1*1024*1024))
{
printf(“%s(大小:%d字节)太大,无法上载此照片,$current[“name”],$current[“size”]);
}
其他的
{
$location='picture/'。$current['name'];
if(移动上传的文件($current['name',$location))
printf(“%s已成功上载,$current[“name]”);
其他的
printf(“失败的
”); } }
我总是在这些行代码上失败:
如果(移动上传的文件($current['name',$lokasi))
它总是返回失败,我知道
$current['name']
只是文件名,而不是zip中的文件。有人知道如何(一个接一个地)在zip中获取文件吗?

说: 此函数检查以确保文件名指定的文件是有效的上载文件(意味着它是通过PHP的HTTP POST上载机制上载的)。可以上载zip存档文件。但是脚本从中提取的文件不是 获取stat条目实际上并不会将数据提取到本地文件系统。为此,您可能会感兴趣和/或

最后,从本文中我了解到,因此我选择使用数组方法提取文件。以下是我解决问题的最终代码:

for ($i=0; $i<$zip->numFiles;$i++) 
        {
            $current = $zip->statIndex($i);
            if($current["size"] > (1*1024*1024))
            {
                printf("%s (size: %d bytes) is too big, failed to upload this image!<br>", $current["name"], $current["size"]);
            }
            else
            {
                $location = $folder.'/'.$folder2.'/';
                if($zip->extractTo($location , array($current['name'])))
                    printf("%s successfully uploaded<br>", $current["name"]);
                else
                    printf("Failed <br />");
            }
        }
for($i=0;$inumFiles;$i++)
{
$current=$zip->statIndex($i);
如果($current[“size”]>(1*1024*1024))
{
printf(“%s(大小:%d字节)太大,无法上载此图像!
”、$current[“name”]、$current[“size”]); } 其他的 { $location=$folder.'/'.$folder2.'/'; if($zip->extractTo($location,array($current['name'])) printf(“%s已成功上载,$current[“name]”); 其他的 printf(“失败的
”); } }