php zip adding non selected files
up vote
0
down vote
favorite
I had a set of files in a folder. from this few will select and adding to zip. But it adding non selected files also.
The sample file names are
EXPLORER_TRM_FDM_147461_B_280.pdf,
EXPLORER_TRM_FDM_147463_B_130.txt,
EXPLORER_TRM_FDM_147470_B_130.pdf,
From this I am selecting only second one but all are coming.
my function is
public function zipFilesDownload($file_names,$archive_file_name,$file_path)
{
$zip = new ZipArchive();
if ($zip->open($archive_file_name, ZIPARCHIVE::CREATE )!==TRUE) {
exit("cannot open <$archive_file_name>n");
}
foreach($file_names as $files){
$zip->addFile($file_path.strtolower($files),$files);
}
$zip->close();
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=$archive_file_name");
header("Pragma: no-cache");
header("Expires: 0");
readfile("$archive_file_name");
exit;
}
$file_names contain only
EXPLORER_TRM_FDM_147463_B_130.txt
but the other two also adding into zip. where I am wrong?
php zip
add a comment |
up vote
0
down vote
favorite
I had a set of files in a folder. from this few will select and adding to zip. But it adding non selected files also.
The sample file names are
EXPLORER_TRM_FDM_147461_B_280.pdf,
EXPLORER_TRM_FDM_147463_B_130.txt,
EXPLORER_TRM_FDM_147470_B_130.pdf,
From this I am selecting only second one but all are coming.
my function is
public function zipFilesDownload($file_names,$archive_file_name,$file_path)
{
$zip = new ZipArchive();
if ($zip->open($archive_file_name, ZIPARCHIVE::CREATE )!==TRUE) {
exit("cannot open <$archive_file_name>n");
}
foreach($file_names as $files){
$zip->addFile($file_path.strtolower($files),$files);
}
$zip->close();
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=$archive_file_name");
header("Pragma: no-cache");
header("Expires: 0");
readfile("$archive_file_name");
exit;
}
$file_names contain only
EXPLORER_TRM_FDM_147463_B_130.txt
but the other two also adding into zip. where I am wrong?
php zip
Usevar_dump()to checking count of$file_namescontent
– Mohammad
Nov 10 at 15:10
this already tried. not working.
– Pradeep.T.P
Nov 10 at 15:31
1
What do you mean by not working? It should return content of$file_namesand you should check that is contain more than one file?
– Mohammad
Nov 10 at 15:32
1
Do you clean/delete zip file on every run?
– Nickolay Olshevsky
Nov 11 at 20:02
I understand the issue. the zip file created in server and next time it loading from cache. I deleted the created zip file after download. So the issue solved. Thanks for the comments
– Pradeep.T.P
Nov 12 at 3:48
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I had a set of files in a folder. from this few will select and adding to zip. But it adding non selected files also.
The sample file names are
EXPLORER_TRM_FDM_147461_B_280.pdf,
EXPLORER_TRM_FDM_147463_B_130.txt,
EXPLORER_TRM_FDM_147470_B_130.pdf,
From this I am selecting only second one but all are coming.
my function is
public function zipFilesDownload($file_names,$archive_file_name,$file_path)
{
$zip = new ZipArchive();
if ($zip->open($archive_file_name, ZIPARCHIVE::CREATE )!==TRUE) {
exit("cannot open <$archive_file_name>n");
}
foreach($file_names as $files){
$zip->addFile($file_path.strtolower($files),$files);
}
$zip->close();
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=$archive_file_name");
header("Pragma: no-cache");
header("Expires: 0");
readfile("$archive_file_name");
exit;
}
$file_names contain only
EXPLORER_TRM_FDM_147463_B_130.txt
but the other two also adding into zip. where I am wrong?
php zip
I had a set of files in a folder. from this few will select and adding to zip. But it adding non selected files also.
The sample file names are
EXPLORER_TRM_FDM_147461_B_280.pdf,
EXPLORER_TRM_FDM_147463_B_130.txt,
EXPLORER_TRM_FDM_147470_B_130.pdf,
From this I am selecting only second one but all are coming.
my function is
public function zipFilesDownload($file_names,$archive_file_name,$file_path)
{
$zip = new ZipArchive();
if ($zip->open($archive_file_name, ZIPARCHIVE::CREATE )!==TRUE) {
exit("cannot open <$archive_file_name>n");
}
foreach($file_names as $files){
$zip->addFile($file_path.strtolower($files),$files);
}
$zip->close();
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=$archive_file_name");
header("Pragma: no-cache");
header("Expires: 0");
readfile("$archive_file_name");
exit;
}
$file_names contain only
EXPLORER_TRM_FDM_147463_B_130.txt
but the other two also adding into zip. where I am wrong?
php zip
php zip
edited Nov 10 at 15:06
Mohammad
11.7k93058
11.7k93058
asked Nov 10 at 14:56
Pradeep.T.P
3314
3314
Usevar_dump()to checking count of$file_namescontent
– Mohammad
Nov 10 at 15:10
this already tried. not working.
– Pradeep.T.P
Nov 10 at 15:31
1
What do you mean by not working? It should return content of$file_namesand you should check that is contain more than one file?
– Mohammad
Nov 10 at 15:32
1
Do you clean/delete zip file on every run?
– Nickolay Olshevsky
Nov 11 at 20:02
I understand the issue. the zip file created in server and next time it loading from cache. I deleted the created zip file after download. So the issue solved. Thanks for the comments
– Pradeep.T.P
Nov 12 at 3:48
add a comment |
Usevar_dump()to checking count of$file_namescontent
– Mohammad
Nov 10 at 15:10
this already tried. not working.
– Pradeep.T.P
Nov 10 at 15:31
1
What do you mean by not working? It should return content of$file_namesand you should check that is contain more than one file?
– Mohammad
Nov 10 at 15:32
1
Do you clean/delete zip file on every run?
– Nickolay Olshevsky
Nov 11 at 20:02
I understand the issue. the zip file created in server and next time it loading from cache. I deleted the created zip file after download. So the issue solved. Thanks for the comments
– Pradeep.T.P
Nov 12 at 3:48
Use
var_dump() to checking count of $file_names content– Mohammad
Nov 10 at 15:10
Use
var_dump() to checking count of $file_names content– Mohammad
Nov 10 at 15:10
this already tried. not working.
– Pradeep.T.P
Nov 10 at 15:31
this already tried. not working.
– Pradeep.T.P
Nov 10 at 15:31
1
1
What do you mean by not working? It should return content of
$file_names and you should check that is contain more than one file?– Mohammad
Nov 10 at 15:32
What do you mean by not working? It should return content of
$file_names and you should check that is contain more than one file?– Mohammad
Nov 10 at 15:32
1
1
Do you clean/delete zip file on every run?
– Nickolay Olshevsky
Nov 11 at 20:02
Do you clean/delete zip file on every run?
– Nickolay Olshevsky
Nov 11 at 20:02
I understand the issue. the zip file created in server and next time it loading from cache. I deleted the created zip file after download. So the issue solved. Thanks for the comments
– Pradeep.T.P
Nov 12 at 3:48
I understand the issue. the zip file created in server and next time it loading from cache. I deleted the created zip file after download. So the issue solved. Thanks for the comments
– Pradeep.T.P
Nov 12 at 3:48
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240155%2fphp-zip-adding-non-selected-files%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Use
var_dump()to checking count of$file_namescontent– Mohammad
Nov 10 at 15:10
this already tried. not working.
– Pradeep.T.P
Nov 10 at 15:31
1
What do you mean by not working? It should return content of
$file_namesand you should check that is contain more than one file?– Mohammad
Nov 10 at 15:32
1
Do you clean/delete zip file on every run?
– Nickolay Olshevsky
Nov 11 at 20:02
I understand the issue. the zip file created in server and next time it loading from cache. I deleted the created zip file after download. So the issue solved. Thanks for the comments
– Pradeep.T.P
Nov 12 at 3:48