library binary-file-storage
Light file storage
compolomus/binary-file-storage
Light file storage
- Monday, September 25, 2017
- by Compolomus
- Repository
- 2 Watchers
- 1 Stars
- 11 Installations
- PHP
- 0 Dependents
- 0 Suggesters
- 0 Forks
- 0 Open issues
- 5 Versions
- 0 % Grown
Koenig BinaryFileStorage
, (*1)
, (*2)
Перехват выгрузки файлов с форм, добавление в хранилище в бинарном виде, получение файлов по хэш ключу
Установка:
composer require compolomus/binary-file-storage, (*3)
Применение:
use Compolomus\BinaryFileStorage\Storage;
require __DIR__ . '/vendor/autoload.php';
$storageConfig = [
'uploadDir' => 'files',
'prefix' => 'prefix',
'firstDirLen' => 1,
];
$storage = new Storage($storageConfig);
$input = $storage->check($_FILES);
/*
Array
(
[0] => Array
(
[name] => 22.png
[ext] => png
[size] => 35359
[type] => image/png
[path] => files\prefix\7\26\726cd0cefcc522784b2f317ca0affe5f
[bin] => 726cd0cefcc522784b2f317ca0affe5f
)
[1] => Array
(
[name] => putty.exe
[ext] => exe
[size] => 454656
[type] => application/x-msdownload
[path] => files\prefix\9\bb\9bb6826905965c13be1c84cc0ff83f42
[bin] => 9bb6826905965c13be1c84cc0ff83f42
)
)
*/
// insert into files ->execute([$input]);
$limit = isset($_GET['limit']) ? abs(intval($_GET['limit'])) : 0;
$file = isset($_GET['file']) ? htmlentities($_GET['file'], ENT_QUOTES, 'UTF-8') : false;
if ($file) {
$obj = $storage->download($file);
if (!is_null($obj)) {
$meta = $storage->getInfoFile($file);
ob_get_level() && ob_end_clean();
header($_SERVER['SERVER_PROTOCOL'] . ' 200 OK');
header('Content-Type: application/force-download');
header('Content-Description: inline; File Transfer');
header('Content-Transfer-Encoding: binary');
if (array_key_exists('name', $meta) & array_key_exists('size', $meta)) {
header('Content-Disposition: attachment; filename="' . $meta['name'] . '";', false);
header('Content-Length: ' . $meta['size']);
}
$speed = 1024 * $limit;
if ($speed > 0) {
$sleep = 1;
} else {
$speed = 8 * 1024;
$sleep = 0;
}
while (!$obj->eof()) {
$buf = $obj->fread($speed);
print($buf);
if ($sleep) {
sleep(1);
}
flush();
}
exit;
} else {
echo '<h1>File not found</h1>';
exit;
}
}
?>
<?php
$count = $storage->count();
if ($count) {
$i = 0;
$files = $count > 10 ? 10 : $count;
$result = $storage->lastInsert($files);
foreach ($result as $key => $value) {
$data = $storage->getInfoFile($key);
echo '<div class="list' . (++$i % 2 ? 2 : 1) . '">'
. ($data ? '<h3>' . $data['name'] . ' ( ' . $storage->fileSize($data['size']) . ' )</h3>' : '')
. '<div class="sub green">
<a href="?file=' . $key . '">Download full speed</a> |
<a href="?file=' . $key . '&limit=128">Download 128 kbps</a> |
<a href="?file=' . $key . '&limit=256">Download 256 kbps</a>
</div>
</div>';
}
}
#echo '
' . print_r($storage->map(), true) . '
';
dev-master
9999999-dev
Light file storage
Sources
Download
MIT
The Requires
by
Koenig
upload
php7
v1.0
1.0.0.0
Light file storage
Sources
Download
MIT
The Requires
by
Koenig
upload
php7
dev-develop
dev-develop
Light file storage
Sources
Download
MIT
The Requires
by
Koenig
upload
php7
v0.9
0.9.0.0
Light file storage
Sources
Download
MIT
The Requires
by
Koenig
upload
php7
v0.8
0.8.0.0
Light file storage
Sources
Download
GPL-3.0
The Requires
by
Koenig
upload
php7