pnd8_rasp/app/engine/core/filesystem.core.php

45 lines
1.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
class DBFileSystem {
static function uploadFile($filename, $is_private, $mimeType = '', $realFileName = '') {
$hashfile = md5_file($filename);
/*
* Логика такая. Чтобы не плодить много одинаковых файлов -
* имя файла берётся из хеша его содержимого
* для одинаковых файлов будет одинаковое имя
* при сохранении смотрим - если такой файл в системе уже есть - не создаем новый
**************************************************/
$fname = $hashfile;
/*
* Создаем структуру директорий для сохранения файла
*/
$fpath = substr($fname,0,2);
$fpath2 = substr($fname,2,2);
@mkdir( _FILES_DIR_ . $fpath . '/' . $fpath2, 0777, true );
$fname = $fpath .'/' . $fpath2 . '/' . $fname;
$fobj = new cobject('_sys_files');
$fobj->set('filename', $fname );
$fobj->set('ext', $mimeType);
$fobj->set('realname', $realFileName);
$fobj->set('private', $is_private);
$fobj->set('hash', $hashfile);
$fobj->save();
if (!file_exists(_FILES_DIR_ . $fname) ) {
rename($filename, _FILES_DIR_ . $fname);
} else {
unlink($filename);
}
return $fobj->id;
}
}
?>