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?










share|improve this question
























  • 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






  • 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








  • 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















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?










share|improve this question
























  • 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






  • 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








  • 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













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?










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 15:06









Mohammad

11.7k93058




11.7k93058










asked Nov 10 at 14:56









Pradeep.T.P

3314




3314












  • 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






  • 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








  • 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










  • 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_names and 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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

The Sandy Post

Danny Elfman

Pages that link to "Head v. Amoskeag Manufacturing Co."