muharihar / FileFinder

Laravel (Local) File Finder Package

Home Page:https://packagist.org/packages/muharihar/file-finder

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Laravel Local File Finder Package

Laravel Local File Finder Package is a simple laravel package that allow finding a file by CONTENT (currently only for .txt file).

Online Demo:

Available Features:

  • List default storage directories and files.
  • Search files and directories By Name.
  • Search files by Content.

REST API Features

Installation

  • Create Laravel Project
$ composer create-project --prefer-dist laravel/laravel laravel_file_finder_5.6_test "5.6.*"
  • Add FileFinder Package
$ cd laravel_file_finder_5.6_test
$ composer require muharihar/file-finder
  • Publish Assets and Default Data Samples
$ php artisan vendor:publish --tag=public --force
  • Add FileFinder Service Provider to laravel application config (config/app.php)
/*
* Package Service Providers...
*/

Muharihar\FileFinder\ServiceProviders\FileFinderServiceProvider::class,
  • Running Application
$ php artisan serve

Test via CURL

1. List default storage directories and files.

Command:

$ curl -v -X GET "http://localhost:8000/file-finder/api/v1.0/default/list-dir-and-files" -H "accept: application/json"

Sample Result: sampleResponse

2. Search files and directories By Name.

Command:

$ curl -X GET "http://localhost:8000/file-finder/api/v1.0/search/by-name?s=b" -H "accept: application/json"

Sample Result:

{
  "searchKey": "b",
  "results": [
    {
      "idx": 2,
      "isDir": true,
      "shortPath": "public/file-finder/folder_animals/folder_birds",
      "extension": "",
      "fileSize": 0,
      "parentPath": "public/file-finder/folder_animals"
    },
    {
      "idx": 12,
      "isDir": true,
      "shortPath": "public/file-finder/folder_fruits/folder_berries",
      "extension": "",
      "fileSize": 0,
      "parentPath": "public/file-finder/folder_fruits"
    },
    {
      "idx": 13,
      "isDir": false,
      "shortPath": "public/file-finder/folder_fruits/folder_berries/file_berries_list.txt",
      "extension": "txt",
      "fileSize": 44,
      "parentPath": "public/file-finder/folder_fruits/folder_berries"
    },
    {
      "idx": 26,
      "isDir": false,
      "shortPath": "public/file-finder/folder_geolocations/folder_cities/file_bg.txt",
      "extension": "txt",
      "fileSize": 633,
      "parentPath": "public/file-finder/folder_geolocations/folder_cities"
    }
  ],
  "resultCount": 4
}

3. Search files by Content.

Command:

$ curl -X GET "http://localhost:8000/file-finder/api/v1.0/search/by-content?s=Obama" -H "accept: application/json"

Sample Result:

{
  "searchKey": "Obama",
  "results": [
    {
      "idx": 41,
      "isDir": false,
      "shortPath": "public/file-finder/folder_peoples/folder_presidents/file_us.txt",
      "extension": "txt",
      "fileSize": 6713,
      "parentPath": "public/file-finder/folder_peoples/folder_presidents",
      "info": {
        "firstPos": 6580,
        "firstStr": "...Obama,http://en.wikipedia.org/wiki/Barack_Obama,20"
      }
    }
  ],
  "resultCount": 1
}

About

Laravel (Local) File Finder Package

https://packagist.org/packages/muharihar/file-finder

License:Apache License 2.0


Languages

Language:PHP 65.9%Language:HTML 34.1%