I'm trying to download multiple files from the server in a zipped folder. Here is the code I have thus far:


<form method="post">
    <input type="checkbox" name="checked[]" value="<?php echo $path; ?>">
    <input type="submit" name="download" value="Download Selected">


     $files = $_POST['checked'];
     foreach ($files as $file ) {

    if(file_exists($_SERVER['DOCUMENT_ROOT'].'/upload/folder/'. $file)){
        require_once(ABSPATH . "wp-admin" . '/includes/file.php');
        $full_path = $_SERVER['DOCUMENT_ROOT'].'/bcg/wp-content/uploads/'. $file;
    else {
        echo 'file doesnt exist';
  • I'm receiving an error stating invalid argument provided for foreach – Michelle M. May 8 '17 at 6:30

remove the brackets from your name="checked" It should just be <input type="checkbox" name="checked" value="<?php echo $path; ?>">

Which would only return one value, so you cant do a foreach loop on one value. You need multiple input fields and then put those values into an array to use in the foreach loop

|improve this answer|||||
  • Thanks for the answer, but the brackets don't need to be removed. – Michelle M. May 8 '17 at 7:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.