Home > Backend Development > PHP Tutorial > PHP关于附件上传解压缩的问题

PHP关于附件上传解压缩的问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-23 14:12:17
Original
818 people have browsed it

在PHP中 一个压缩包上传,我已经能够解压开来。
现在如何在解压的同时重命名,并且放到另一个目录下啊?
请大神指教。
解压程式
$zip = zip_open("/php/test/test.zip");

if ($zip) {
  while ($zip_entry = zip_read($zip)) {
     $fp = fopen("/php/".zip_entry_name($zip_entry), 'w');
     if (zip_entry_open($zip, $zip_entry, "r")) {
     $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));

     fwrite($fp,'$buf');
     zip_entry_close($zip_entry);
     fclose($fp);
     }
    }
  zip_close($zip);
 }
求在中间加上重命名与另存到一个目录下的功能。。。。。


回复讨论(解决方案)

解压是解压,重命名是重命名
干嘛把不相干的事情硬揉在一起?
分别进行就是了

在解压的时候 将里面的文件重命名 放到另一个目录下面去啊

解压是解压,重命名是重命名
干嘛把不相干的事情硬揉在一起?
分别进行就是了

你这不是已经放到另外的目录了吗? "/php/".zip_entry_name($zip_entry)
如果你要将包中的文件在解压时换名,至少也得给个换名规则或是新旧名称对照表吧?

明白了,换名是 只取前五个字符 然后后缀名不变。

你这不是已经放到另外的目录了吗? "/php/".zip_entry_name($zip_entry)
如果你要将包中的文件在解压时换名,至少也得给个换名规则或是新旧名称对照表吧?

zip_entry_name($zip_entry) 得到的是包中的文件名
你用字符串函数处理一下,生成目标文件名就是了

知道了 谢谢啦 /ui/scripts/csdn/Plugin/001/face/63.gif][/img]

我 echo "zip_entry_name($zip_entry)" 出来的是Array 啊。。。。怎么回事。。。。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template