制作一个临时目录以将zipfile解压缩到 [英] Making a temporary dir for unpacking a zipfile into

查看:180
本文介绍了制作一个临时目录以将zipfile解压缩到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本,用于检查包含许多匹配的PDF +文本文件的zip文件.我想解压缩,或者以某种方式从zip文件中读取文本文件,然后从文本文件中挑选一些信息以查看文件版本正确.

I have a script that checks a zipfile containing a number of matching PDF+textfiles. I want to unpack, or somehow read the textfiles from the zipfile, and just pick out some information from the textfile to see that the file version is correct.

我当时正在查看tempnam()函数以查找创建临时目录的等效项,但也许有人可以更好地解决该问题.

I was looking at the tempnam() function to find an equivalent to make a tempdir, but maybe someone has a better solution for the problem.

索引文件看起来像这样. (->用于TAB字符). 我已经完成了从文本文件中提取版本并检查其版本是否正确的功能,它只是解压缩,tmpdir或我正在寻找的其他解决方案.

The indexfile looks something like this. (-> is for TAB char). I have made the function to extract the version from the textfile and to check if its correct already, its only the unpacking, tmpdir or some other solution im looking for.

1000->filename->file version->program version->customer no->company no->distribution
2000->pagenumber->more info->more info->...

推荐答案

非常简单(我从PHP手册中摘了一部分内容):

quite easy (I took partly it from the PHP manual):

<?php

function tempdir() {
    $tempfile=tempnam(sys_get_temp_dir(),'');
    // you might want to reconsider this line when using this snippet.
    // it "could" clash with an existing directory and this line will
    // try to delete the existing one. Handle with caution.
    if (file_exists($tempfile)) { unlink($tempfile); }
    mkdir($tempfile);
    if (is_dir($tempfile)) { return $tempfile; }
}

/*example*/

echo tempdir();
// returns: /tmp/8e9MLi

请参阅: https://www.php.net/manual/zh/function.tempnam.php

请在下面查看Will的解决方案.

=>我的答案不再是公认的答案.

=> My answer should not be the accepted answer anymore.

这篇关于制作一个临时目录以将zipfile解压缩到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆