PHPackages                             dsijak/sharefile - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. dsijak/sharefile

ActiveLibrary[Security](/categories/security)

dsijak/sharefile
================

Share files protected with access token.

v0.3(4y ago)012MITPHPPHP &gt;=7.0

Since Jun 6Pushed 4y ago1 watchersCompare

[ Source](https://github.com/damir-sijakovic/sharefile)[ Packagist](https://packagist.org/packages/dsijak/sharefile)[ RSS](/packages/dsijak-sharefile/feed)WikiDiscussions main Synced 6d ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

Sharefile
=========

[](#sharefile)

Share files protected with access token.
----------------------------------------

[](#share-files-protected-with-access-token)

Before use configure `vendor/dsijak/sharefile/project/Etc/config.php`.
Setting `DS_SF_MODE` mode to `production` will disable browser error log output.

### Install

[](#install)

```
        composer require dsijak/sharefile

```

### Usage

[](#usage)

First set directory with files in `config.php => DS_SF_FILE_DIR`. This
directory should be not accessable via url.

Acquire file item:

```
        $accessToken = $sharefile->acquireItem('vid.mp4');

```

File must exist and allowed filetype must be specified in `config.php`.
`acquireItem` method will store file, key and keyExpiration data into
sqlite/mariadb database. `acquireItem` method returns access token or key.
After this, you can send this key/token to whomever you want to have access
to acquired file.

Obtain file item:

```
        $sharefile->obtainItem('vid.mp4', 'f8b32a778acfaaaa');

```

This will generate new file with header inside your browser.
`obtainItem` method must be executed from new route or after redirected.
If key has expired, only text message will be generated.

### What is this useful for?

[](#what-is-this-useful-for)

For example, when you are selling digital items. When someone buys your
photography or ebook, you can send them file key. Key will be valid
only for amount of time you specify in the `config.php`.

For example, you can mail link `yoursite.com/obtainItem?filename=vid.mp4&key=f8b32a778acfaaaa`Then you can take file and key params:

```
        $sharefile->obtainItem($filename, $key);

```

This will generate acquired document or text document with message.

### Error messages

[](#error-messages)

Both `acquireItem` and `obtainItem` methods accept additional reference
argument to pass back error message.

```
        $errorMessage = '';
        $accessToken = $sharefile->acquireItem('ebook.pdf', $errorMessage);

        if (!$accessToken)
        {
            error_log($errorMessage);
        }

```

### Short usage example

[](#short-usage-example)

```
        use Sharefile\Sharefile;

        $sharefile = new Sharefile();
        $errorMessage = '';
        $accessToken = $sharefile->acquireItem('vid.mp4', $errorMessage);
        if (!$accessToken)
        {
            error_log($errorMessage);
        }

        $sharefile->obtainItem('vid.mp4', $accessToken);
        //renders file

```

### MariaDB Usage

[](#mariadb-usage)

Run this query:

```
        CREATE DATABASE ds_sharefile;
        CREATE USER 'ds_sharefile'@'localhost' IDENTIFIED BY 'ds_sharefile';
        GRANT ALL ON ds_sharefile.* TO 'ds_sharefile'@'localhost';
        USE ds_sharefile;

```

Edit: `vendor/dsijak/sharefile/project/Etc/config.php`.
Set `DS_SF_MODEL_TYPE` to `mariadb`.
Database user/pass are also set there.
To use existing PDO object, pass it to constructor together with database name:

```
        $sharefile = new Sharefile($pdoObj, 'myDatabaseName');

```

### Advanced methods

[](#advanced-methods)

These methods returns data/null or true/false.
You can get advanced methods through `advanced` property:

```
        $x = $sharefile->advanced->databaseCreatedAt($errorMessage);

```

#### Methods:

[](#methods)

**fileExists($filename, &amp;$eMessage=null)**
Checks if file exists.

**emptyDatabase(&amp;$eMessage=null)**
Removes all aquired items from database.

**databaseCreatedAt(&amp;$eMessage=null)**
Returns creation date.

**generateFileKey($filename, &amp;$eMessage=null)**
Generates key for filename and stores everything.

**deleteKey($key, &amp;$eMessage=null)**
Deletes key, if exists.

**getGeneratedFileKeyRecord($filename, $key, &amp;$eMessage=null)**
Returns key/filename, if exists.

**isKeyValid($filename, $key, &amp;$eMessage=null)**
Checks if key/token is valid.

**generateBase64ImageFile($filename, &amp;$eMessage=null)**
Generates html img element with base64 image. This is ment to be used with images.

**generateHeaderFile($filename)**
Generates file as HTTP respose.

**generateHeaderMessage($message)**
Generates text file as HTTP respose with $message.

### Have Fun

[](#have-fun)

`Developed and tested under 5.4.118-1-manjaro/xfce/docker/portainer`

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1806d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fe7c21126ed15e85d82bfb995f5c67f82e463c3a695e7db37f6fe8ebc49b65a8?d=identicon)[dsijak](/maintainers/dsijak)

---

Top Contributors

[![damir-sijakovic](https://avatars.githubusercontent.com/u/50234352?v=4)](https://github.com/damir-sijakovic "damir-sijakovic (1 commits)")

---

Tags

filesharingphpsqlite

### Embed Badge

![Health badge](/badges/dsijak-sharefile/health.svg)

```
[![Health](https://phpackages.com/badges/dsijak-sharefile/health.svg)](https://phpackages.com/packages/dsijak-sharefile)
```

###  Alternatives

[defuse/php-encryption

Secure PHP Encryption Library

3.9k162.4M214](/packages/defuse-php-encryption)[roave/security-advisories

Prevents installation of composer packages with known security vulnerabilities: no API, simply require it

2.9k97.3M6.4k](/packages/roave-security-advisories)[mews/purifier

Laravel 5/6/7/8/9/10 HtmlPurifier Package

2.0k16.7M113](/packages/mews-purifier)[robrichards/xmlseclibs

A PHP library for XML Security

41278.1M118](/packages/robrichards-xmlseclibs)[bjeavons/zxcvbn-php

Realistic password strength estimation PHP library based on Zxcvbn JS

86917.5M63](/packages/bjeavons-zxcvbn-php)[enlightn/security-checker

A PHP dependency vulnerabilities scanner based on the Security Advisories Database.

33732.2M110](/packages/enlightn-security-checker)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
