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 9086761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:34:01+00:00 2026-06-16T21:34:01+00:00

I am using a mongo database and and PHP to compare file meta information

  • 0

I am using a mongo database and and PHP to compare file meta information to a directory of files to see whats missing where. We then return an associative array of files and database to see whats missing and from where.

Note: You do not need to know mongo in order to help me out.

For example, if I delete a file from the directory, yet there is an entry in the database my array will look like such:

array(2) {
  'File System' =>
  array(1) {
    [0] =>
    string(28) "50e72bce045aca4c04000004.txt"
  }
  'Database' =>
  array(0) {
  }
}

The code for this check is done bellow:

public function compareDatabaseToDirectory(){
    // Fetch all file meta information
    $files = $this->_model->fetchAll(array());

    // Create a file based on id and extension.
    foreach($files as $id=>$model){
       $dataBaseEntries[] = $id . $model->fileExtension;
    }

    // Get all files in our directory
    $directoryFiles = preg_grep('/^([^.])/', scandir($this->getDestination()));

    // Get the differneces of files
    $differences = array_diff($dataBaseEntries, $directoryFiles);

    // Check if missing from database OR missing from file system
    $missingFromDataBase = array_diff($differences, $dataBaseEntries);
    $missingFromFileSystem = array_diff($differences, $directoryFiles);

    // Create an associative array
    $filesMissing = array(
          'File System' => $missingFromFileSystem,
          'Database' => $missingFromDataBase
   );

   // Return results.
   return $filesMissing;
}

All were doing here is using a mongo id and appending it to a file extension to create said file.

we compare the array of files against that in the directory of files and return the differences.

In my test all we do is:

public function testComapreDatabaseToFileSystemMissingFile(){
    $this->resetNoSqlDatabase();

    unlink(APPLICATION_PATH . '/data/uploadedFiles/testing/50e72bce045aca4c04000004.txt');
    $result = $this->_file->compareDatabaseToDirectory();

    $expectedArray = array(
        'File System' => array(
            '50e72bce045aca4c04000004.txt'  
        ),
        'Database' => array(),                      
    );


    $this->assertEquals($result, $expectedArray);

}

Which returns me the array you see above. How ever if I replicate the same concept in the browser my array you see above is empty when it should not be.

Any ideas?

  • 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-16T21:34:02+00:00Added an answer on June 16, 2026 at 9:34 pm

    It was a folder permissions issue. We created the folder before setting the folder to 0777.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using django-nonrel, Postgre as a database and Mongo as file store. my
I'm using Mongoose to manage a Mongo database. My connection file is quite simple:
We are using mongo db to store certain records in production database. We see
I am using PHP/Mongo to query a data set like the following: { description:
I'm using Spring Data for Mongo on an existing database. The previous application used
I am trying to export from a mongo database using the following mongoexport command
I need to store some files in my Mongo database and came across these
I'm trying to create a seed file to populate my mongo database. The following
I'm currently trying to get a Mongo database running alongside Devise. I'm using Rails
. I am building an utility to manage mongo database. I am using visual

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.