Archived
1
0

Implement video upload to posts

This commit is contained in:
Marcel
2018-12-30 18:52:30 +01:00
parent 1f3e0243cf
commit ebb5c473f6
11 changed files with 1063 additions and 571 deletions

View File

@@ -11,8 +11,24 @@ class FileModel extends CI_Model
parent::__construct();
}
private function getPath($fileName, $userContent) {
return 'files/' . ($userContent ? 'userContent/' : '') . $fileName;
private function getPath($fileName, $user) {
return 'files/' . ($user != null ? 'userContent/' . $user . '/' : '') . $fileName;
}
private function addToDatabase($name, $originalName, $type, $size, $path, $user) {
$userID = NULL;
if(is_string($user)) {
$user = $this->db->query('SELECT ID FROM users WHERE username = lower(?)', [$user])->result_array();
if(!empty($user)) {
$userID = $user[0]['ID'];
}
} else if(is_integer($user)) {
$userID = $user;
}
$this->db->query('INSERT INTO files (name, original_name, type, size, path, user) VALUES (?, ?, ?, ?, ?, ?)', [$name, $originalName, $type, $size, $path, $userID]);
$this->db->cache_delete('admin', 'files');
}
public function uploadFile($original_name, $tmpname, $size, $type, $userContent = true)
@@ -28,20 +44,51 @@ class FileModel extends CI_Model
$target_file = str_replace('\\', '/', $target_file);
$this->db->query('INSERT INTO files (name, original_name, type, size, path, isUserData) VALUES (?, ?, ?, ?, ?, ?)', [$name, $original_name, $type, $size, $target_file, $userContent]);
$this->db->cache_delete('admin', 'files');
$this->addToDatabase($name, $original_name, $type, $size, $target_file, $userContent);
echo shell_exec('python /var/www/codeigniter/duplicates.py');
return "/f/" . $name;
}
public function uploadImage($name, $max_size, $originalname, $max_width, $userContent = true) {
$config['upload_path'] = '.' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . ($userContent ? 'userContent' . DIRECTORY_SEPARATOR : '');
public function uploadVideo($name, $max_size, $originalName, $max_width, $user = null) {
$path = '.' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR;
if($user !== null) {
$path .= 'userContent' . DIRECTORY_SEPARATOR . $user . DIRECTORY_SEPARATOR;
}
$config['upload_path'] = $path;
if(!file_exists($path)) {
mkdir($path, 0777);
}
$config['allowed_types'] = 'mp4';
$config['max_size'] = $max_size;
$config['file_name'] = $this->generateName() . '.' . pathinfo(basename($originalName), PATHINFO_EXTENSION);
$this->load->library('upload', $config);
if(!$this->upload->do_upload($name)) {
return null;
} else {
$data = $this->upload->data();
$this->upload->display_errors();
$this->addToDatabase($data['raw_name'], $originalName, $data['file_type'], $data['file_size'] * 1024, $this->getPath($data['file_name'], $user), $user);
return '/f/' . $data['raw_name'];
}
}
public function uploadImage($name, $max_size, $originalName, $max_width, $user = null) {
$config['upload_path'] = '.' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR;
if($user != null) {
$config['upload_path'] .= 'userContent' . DIRECTORY_SEPARATOR . $user . DIRECTORY_SEPARATOR;
}
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = $max_size;
$config['file_name'] = $this->generateName() . "." . pathinfo(basename($originalname), PATHINFO_EXTENSION);
$config['file_name'] = $this->generateName() . "." . pathinfo(basename($originalName), PATHINFO_EXTENSION);
$this->load->library('upload', $config);
@@ -60,9 +107,7 @@ class FileModel extends CI_Model
$this->image_lib->resize();
$this->db->query('INSERT INTO files (name, original_name, type, size, path, isUserData) VALUES (?, ?, ?, ?, ?, ?)', [$data['raw_name'], $originalname, $data['file_type'], $data['file_size'] * 1024, $this->getPath($data['file_name'], $userContent), $userContent]);
$this->db->cache_delete('admin', 'files');
$this->addToDatabase($data['raw_name'], $originalName, $data['file_type'], $data['file_size'] * 1024, $this->getPath($data['file_name'], $user), $user);
echo shell_exec('python /var/www/codeigniter/duplicates.py');
@@ -164,6 +209,16 @@ class FileModel extends CI_Model
return $result;
}
public function getFileID($name, $userID = null) {
$result = $this->db->query('SELECT ID FROM files WHERE name = ? AND user = ?', [$name, $userID])->result_array();
return $result;
}
public function getFilePath($name, $userID = null) {
$result = $this->db->query('SELECT path FROM files WHERE name = ? AND user = ?', [$name, $userID])->result_array();
return !empty($result) ? $result[0]['path'] : null;
}
public function delete($id) {
$filePath = $this->db->query('SELECT path FROM files WHERE ID = ? LIMIT 1', [$id])->result_array()[0];
unlink($filePath['path']);