forked from gitbot/uguu
revert
This commit is contained in:
parent
48233fb137
commit
30bd416912
@ -4,6 +4,7 @@ class UploadedFile
|
|||||||
{
|
{
|
||||||
/* Public attributes */
|
/* Public attributes */
|
||||||
public $name;
|
public $name;
|
||||||
|
public $mime;
|
||||||
public $size;
|
public $size;
|
||||||
public $tempfile;
|
public $tempfile;
|
||||||
public $error;
|
public $error;
|
||||||
@ -28,48 +29,4 @@ class UploadedFile
|
|||||||
|
|
||||||
return $this->sha1;
|
return $this->sha1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/**
|
|
||||||
* MIME-type
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
|
|
||||||
private $mime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetches the MIME type of the file
|
|
||||||
*
|
|
||||||
* @return string|false $mime
|
|
||||||
*/
|
|
||||||
|
|
||||||
public function getMime(){
|
|
||||||
if (!$this->mime) {
|
|
||||||
$finfo = finfo_open(FILEINFO_MIME_TYPE);
|
|
||||||
$this->mime = finfo_file($finfo, $file->tempfile);
|
|
||||||
finfo_close($finfo);
|
|
||||||
}
|
|
||||||
return $this->mime;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extension of file
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
|
|
||||||
private $ext;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetches the extension of the file
|
|
||||||
*
|
|
||||||
* @return string|false $ext
|
|
||||||
*/
|
|
||||||
|
|
||||||
public function getExt(){
|
|
||||||
if (!$this->ext) {
|
|
||||||
$this->ext = pathinfo($file->name, PATHINFO_EXTENSION);
|
|
||||||
}
|
|
||||||
return $this->ext;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -31,7 +31,7 @@ define('UGUU_ADMIN_USER', 'admin');
|
|||||||
define('UGUU_ADMIN_PASS', '$2y$12$.NHW25QBD/XPSYkNe6tEtObwEXsJeiQIo3xWidU.21ECkFMK.SE8C%');
|
define('UGUU_ADMIN_PASS', '$2y$12$.NHW25QBD/XPSYkNe6tEtObwEXsJeiQIo3xWidU.21ECkFMK.SE8C%');
|
||||||
|
|
||||||
/** Log IP of uploads */
|
/** Log IP of uploads */
|
||||||
define('LOG_IP', 'false');
|
define('UGUU_LOG_IP', 'false');
|
||||||
|
|
||||||
/** Anti-dupe files */
|
/** Anti-dupe files */
|
||||||
define('UGUU_DUPE', 'false');
|
define('UGUU_DUPE', 'false');
|
||||||
|
@ -24,8 +24,12 @@ function generateName($file)
|
|||||||
// We start at N retries, and --N until we give up
|
// We start at N retries, and --N until we give up
|
||||||
$tries = UGUU_FILES_RETRIES;
|
$tries = UGUU_FILES_RETRIES;
|
||||||
$length = UGUU_FILES_LENGTH;
|
$length = UGUU_FILES_LENGTH;
|
||||||
|
//Get EXT
|
||||||
$ext = $file->getExt();
|
$ext = pathinfo($file->name, PATHINFO_EXTENSION);
|
||||||
|
//Get mime
|
||||||
|
$finfo = finfo_open(FILEINFO_MIME_TYPE);
|
||||||
|
$type_mime = finfo_file($finfo, $file->tempfile);
|
||||||
|
finfo_close($finfo);
|
||||||
|
|
||||||
// Check if extension is a double-dot extension and, if true, override $ext
|
// Check if extension is a double-dot extension and, if true, override $ext
|
||||||
$revname = strrev($file->name);
|
$revname = strrev($file->name);
|
||||||
@ -57,7 +61,7 @@ function generateName($file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Check if mime is blacklisted
|
//Check if mime is blacklisted
|
||||||
if (in_array($file->getMime(), unserialize(CONFIG_BLOCKED_MIME))) {
|
if (in_array($type_mime, unserialize(CONFIG_BLOCKED_MIME))) {
|
||||||
http_response_code(415);
|
http_response_code(415);
|
||||||
throw new Exception ('Extension type not allowed.');
|
throw new Exception ('Extension type not allowed.');
|
||||||
exit(0);
|
exit(0);
|
||||||
@ -101,7 +105,7 @@ function uploadFile($file)
|
|||||||
// Check if a file with the same hash and size (a file which is the same)
|
// Check if a file with the same hash and size (a file which is the same)
|
||||||
// does already exist in the database; if it does, return the proper link
|
// does already exist in the database; if it does, return the proper link
|
||||||
// and data. PHP deletes the temporary file just uploaded automatically.
|
// and data. PHP deletes the temporary file just uploaded automatically.
|
||||||
if(UGUU_DUPE){
|
if(UGUU_DUPE == 'true'){
|
||||||
$q = $db->prepare('SELECT filename, COUNT(*) AS count FROM files WHERE hash = (:hash) '.
|
$q = $db->prepare('SELECT filename, COUNT(*) AS count FROM files WHERE hash = (:hash) '.
|
||||||
'AND size = (:size)');
|
'AND size = (:size)');
|
||||||
$q->bindValue(':hash', $file->getSha1(), PDO::PARAM_STR);
|
$q->bindValue(':hash', $file->getSha1(), PDO::PARAM_STR);
|
||||||
@ -112,7 +116,7 @@ function uploadFile($file)
|
|||||||
return [
|
return [
|
||||||
'hash' => $file->getSha1(),
|
'hash' => $file->getSha1(),
|
||||||
'name' => $file->name,
|
'name' => $file->name,
|
||||||
'url' => UGUU_URL.rawurlencode($result['filename']),
|
'url' => POMF_URL.rawurlencode($result['filename']),
|
||||||
'size' => $file->size,
|
'size' => $file->size,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -146,7 +150,7 @@ function uploadFile($file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add it to the database
|
// Add it to the database
|
||||||
if(LOG_IP){
|
if(UGUU_LOG_IP == 'true'){
|
||||||
$q = $db->prepare('INSERT INTO files (hash, originalname, filename, size, date, ip) VALUES (:hash, :orig, :name, :size, :date, :ip)');
|
$q = $db->prepare('INSERT INTO files (hash, originalname, filename, size, date, ip) VALUES (:hash, :orig, :name, :size, :date, :ip)');
|
||||||
}else{
|
}else{
|
||||||
$ip = '0';
|
$ip = '0';
|
||||||
@ -204,6 +208,7 @@ function refiles($files)
|
|||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
$f = new UploadedFile();
|
$f = new UploadedFile();
|
||||||
$f->name = $file['name'];
|
$f->name = $file['name'];
|
||||||
|
$f->mime = $file['type'];
|
||||||
$f->size = $file['size'];
|
$f->size = $file['size'];
|
||||||
$f->tempfile = $file['tmp_name'];
|
$f->tempfile = $file['tmp_name'];
|
||||||
$f->error = $file['error'];
|
$f->error = $file['error'];
|
||||||
|
Loading…
Reference in New Issue
Block a user