Update README.md and sync files.
This commit is contained in:
parent
dc7f0025ef
commit
da93d643d9
11 changed files with 763 additions and 2 deletions
88
classes/Upload.php
Normal file
88
classes/Upload.php
Normal file
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
class Upload
|
||||
{
|
||||
private $file;
|
||||
private $file_name;
|
||||
private $file_size;
|
||||
private $file_tmp;
|
||||
private $file_type;
|
||||
private $file_ext;
|
||||
private $file_path;
|
||||
private $extensions = array("mp3", "zip");
|
||||
private $upload_dir = "uploads/";
|
||||
private $errors = array();
|
||||
private $ok = false;
|
||||
private $config;
|
||||
private $uuid = "";
|
||||
|
||||
|
||||
public function __construct($file, $config)
|
||||
{
|
||||
$this->file = $file;
|
||||
$this->file_name = $file['name'];
|
||||
$this->file_size = $file['size'];
|
||||
$this->file_tmp = $file['tmp_name'];
|
||||
$this->file_type = $file['type'];
|
||||
$this->config = $config;
|
||||
$ext = explode('.', $file['name']);
|
||||
$this->file_ext = strtolower(end($ext));
|
||||
$this->uuid = uniqid();
|
||||
|
||||
}
|
||||
|
||||
private function check_file_size(): bool
|
||||
{
|
||||
if ($this->file_size > $this->config['uploads']['max_file_size']){
|
||||
$this->errors[] = "File size is too large";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private function check_file_extension(): bool
|
||||
{
|
||||
if (!in_array($this->file_ext, $this->extensions)){
|
||||
$this->errors[] = "Invalid file extension";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private function check_file_exists(): bool
|
||||
{
|
||||
if (file_exists($this->upload_dir . $this->file_name)){
|
||||
$this->errors[] = "File already exists";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private function move_file(): bool
|
||||
{
|
||||
if (move_uploaded_file($this->file_tmp, $this->upload_dir . $this->uuid)){
|
||||
$this->file_path = $this->upload_dir . $this->uuid;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function dump_all()
|
||||
{
|
||||
$array = array(
|
||||
"file" => $this->file,
|
||||
"file_name" => $this->file_name,
|
||||
"file_size" => $this->file_size,
|
||||
"file_tmp" => $this->file_tmp,
|
||||
"file_type" => $this->file_type,
|
||||
"file_ext" => $this->file_ext,
|
||||
"file_path" => $this->file_path,
|
||||
"extensions" => $this->extensions,
|
||||
"upload_dir" => $this->upload_dir,
|
||||
"errors" => $this->errors,
|
||||
"ok" => $this->ok,
|
||||
"uuid" => $this->uuid
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue