▼やりたいこと
zipファイルを解凍したい
▼躓いていること
zipper.phpのextractToというメソッドを使用すると
「Call to a member function each() on null」のエラーが出ており、そこから進めずにいる。
色々調べたのですが、必要としているオブジェクトメソッドが生成されていないとのことでした。
(参考:https://php1st.com/2025/)
extractToはphpのメソッドなので、渡している引数に問題があるのではないかと疑っているのですが、
何が間違っているのかわからない状態です。
尚、ディレクトリは指定された場所にできていましたが、中身はない状態です。(解凍ができていないので当然なのですが)
どうかお力いただけないでしょうか。
宜しくお願いいたします。
【zipper.php】
public function extractTo($path, array $files = [], $methodFlags = self::BLACKLIST) { if (!$this->file->exists($path) && !$this->file->makeDirectory($path, 0755, true)) { throw new \RuntimeException('Failed to create folder'); } if ($methodFlags & self::EXACT_MATCH) { $matchingMethod = function ($haystack) use ($files) { return in_array($haystack, $files, true); }; } else { $matchingMethod = function ($haystack) use ($files) { return starts_with($haystack, $files); }; } if ($methodFlags & self::WHITELIST) { $this->extractFilesInternal($path, $matchingMethod); } else { // blacklist - extract files that do not match with $matchingMethod $this->extractFilesInternal($path, function ($filename) use ($matchingMethod) { return !$matchingMethod($filename); }); } }
【zipPresenter.php】
$directory_name = "abc/"; $file_data = hoge.zip; $zip = Zipper::extractTo($directory_name, $file_data,$methodFlags=[]); $zip->close();
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/08/10 07:48 編集
2018/08/10 08:23
2018/08/10 13:12