2017-02-16 18 views
0

ファイルを圧縮するためにダウンロードボタンを作成しようとしました。配列内に複数のファイルを設定すると、エラーが発生します。enter image description herePHPは複数のファイルをZIPエラーとしてダウンロードします

"files/path/to/8717953176714.jpg"をハードコードすると動作します。

<?php 
 

 
//print_r($_POST["foto"]); 
 

 
$files = array($_POST["foto"]); 
 
$random = rand(1000000000, 9999999999); 
 
$zipname = 'file'.$random.'.zip'; 
 
$zip = new ZipArchive; 
 
$zip->open($zipname, ZipArchive::CREATE); 
 
foreach ($files as $file) { 
 
    $zip->addFile($file); 
 
} 
 

 
$zip->close(); 
 

 
$filename = $zipname; 
 

 
header('Content-type: application/zip'); 
 
header('Content-Disposition: attachment; filename="' . $filename . '"'); 
 
header('Content-length: ' . filesize($filename)); 
 
readfile($filename); 
 
$file = fopen('iplog.txt', 'a', 1); 
 
$ipz = getenv("REMOTE_ADDR"); 
 
$text = "$ipz\n"; 
 
fwrite($file, $text); 
 
fclose($file); 
 

 
?>

答えて

0

は、ここに私のコードです。私は配列に配列を作りました。だからそれは良い道を得られなかった。代わりに

$files = array($_POST["foto"]);

0

この変更を試みる:問題だった

$zipname =getcwd()'/file'.$random.'.zip'; 
+0

$files = $_POST["foto"];

私には何も与えません。は動作しません:( – Horizon

+0

echo $ zipname;パスがOKかどうかを確認します –

関連する問題