Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8351315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:35:41+00:00 2026-06-09T08:35:41+00:00

Possible Duplicate: scandir fail to open directory I fixed part of my scandir() problem,

  • 0

Possible Duplicate:
scandir fail to open directory

I fixed part of my scandir() problem, but I do not like the arrays. I want it to display the files that are uploaded and give links to them so you would be able to click the images and view them, or click zip files and download them. Problem is I have no idea how to do this.

<?php
 $files = scandir('../snaps'); 
 print_r($files);
 ?>

My scandir so far.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T08:35:43+00:00Added an answer on June 9, 2026 at 8:35 am

    If you give more details it might help, I think this code will help for the links:

        <?php
    $files = scandir('../snaps'); 
    
    foreach($files as $file){ ?>
    <a href="../<?php echo $file; ?>"><?php echo $file; ?></a>
    <?
    }
    ?>
    

    This is a function to create the Zip files

        <?
    function create_zip($files = array(),$destination = '',$overwrite = false, $distill_subdirectories = true) {
      //if the zip file already exists and overwrite is false, return false
      if(file_exists($destination) && !$overwrite) { return false; }
      //vars
      $valid_files = array();
      //if files were passed in...
      if(is_array($files)) {
    
        //cycle through each file
        foreach($files as $file) {
          //make sure the file exists
          if(file_exists($file)) {
              // echo 1;
            $valid_files[] = $file;
          }
        }
      }
      //if we have good files...
      if(count($valid_files)) {
        //create the archive
        $zip = new ZipArchive();
        if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
          return false;
        }
        //add the files
        foreach($valid_files as $file) {
            if ($distill_subdirectories) {
            $zip->addFile($file, basename($file) );
            } else {
            $zip->addFile($file, $file);
            }
            }
        //debug
        //echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status;
    
        //close the zip -- done!
        $zip->close();
    
    
        //check to make sure the file exists
        //return file_exists($destination);
        header("Content-type: application/octet-stream");
        header("Content-disposition: attachment; filename={$destination}");
        ob_clean();
        flush();
        readfile($destination);
        //echo $destination;
      }
      else
      {
        return false;
      }
    }
    
    ?>
    

    And this is the way you can call it:

        $files = scandir('../snaps');
    
        $to_zip = array();
        foreach($files as $file){
            if($file != "." AND $file !=".."){
                $to_zip[] = $folder . "/".$file;
            }
        } 
    
    $zip = create_zip($to_zip, "test.zip", true);   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Check whether a Directory Exists in PHP I am trying scandir() to
Possible Duplicate: PHP list of specific files in a directory use php scandir($dir) and
Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want
Possible Duplicate: How to do the vector of sets in C++? I want to
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: check whether internet connection is available with C# I just want to
Possible Duplicate: Opening url in new tab while i am doing window.open(), my page
Possible Duplicate: Can a Bash script tell what directory it's stored in? Is there
Possible Duplicate: C# driver development? I would like to know if I can do
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.