Holiday changes ;)
This commit is contained in:
@@ -11,9 +11,13 @@ class FileModel extends CI_Model
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function uploadFile($original_name, $tmpname, $size, $type)
|
||||
private function getPath($fileName, $userContent) {
|
||||
return 'files/' . ($userContent ? 'userContent/' : '') . $fileName;
|
||||
}
|
||||
|
||||
public function uploadFile($original_name, $tmpname, $size, $type, $userContent = true)
|
||||
{
|
||||
$target_dir = "files" . DIRECTORY_SEPARATOR;
|
||||
$target_dir = "files" . DIRECTORY_SEPARATOR . ($userContent ? 'userContent' . DIRECTORY_SEPARATOR : '');
|
||||
$filetype = pathinfo(basename($original_name), PATHINFO_EXTENSION);
|
||||
$target_file = $target_dir . $this->generateName() . '.' . $filetype;
|
||||
$name = explode('.' . $filetype, explode(DIRECTORY_SEPARATOR, $target_file)[1])[0];
|
||||
@@ -22,13 +26,13 @@ class FileModel extends CI_Model
|
||||
die('File couldn\'t be uploaded!');
|
||||
}
|
||||
|
||||
$this->db->query('INSERT INTO files (name, original_name, type, size, path) VALUES (?, ?, ?, ?, ?)', [$name, $original_name, $type, $size, $target_file]);
|
||||
$this->db->query('INSERT INTO files (name, original_name, type, size, path, isUserData) VALUES (?, ?, ?, ?, ?, ?)', [$name, $original_name, $type, $size, $target_file, $userContent]);
|
||||
|
||||
return "/file/open/" . $name;
|
||||
return "/f/" . $name;
|
||||
}
|
||||
|
||||
public function uploadImage($name, $max_size, $originalname, $max_width) {
|
||||
$config['upload_path'] = './files/';
|
||||
public function uploadImage($name, $max_size, $originalname, $max_width, $userContent = true) {
|
||||
$config['upload_path'] = '.' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . ($userContent ? 'userContent' . DIRECTORY_SEPARATOR : '');
|
||||
$config['allowed_types'] = 'gif|jpg|png';
|
||||
$config['max_size'] = $max_size;
|
||||
$config['file_name'] = $this->generateName() . "." . pathinfo(basename($originalname), PATHINFO_EXTENSION);
|
||||
@@ -50,13 +54,65 @@ class FileModel extends CI_Model
|
||||
|
||||
$this->image_lib->resize();
|
||||
|
||||
$this->db->query('INSERT INTO files (name, original_name, type, size, path) VALUES (?, ?, ?, ?, ?)', [$data['raw_name'], $originalname, $data['file_type'], $data['file_size'] * 1024, 'files/' . $data['file_name']]);
|
||||
$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]);
|
||||
return '/f/' . $data['raw_name'];
|
||||
}
|
||||
}
|
||||
|
||||
public function uploadFileByContent($content, $original_name, $fullType, $fileSize) {
|
||||
$target_dir = "files" . DIRECTORY_SEPARATOR;
|
||||
public function uploadCroppedImage($name, $max_size, $originalname, $width, $height, $userContent = true) {
|
||||
$config['upload_path'] = '.' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . ($userContent ? 'userContent' . DIRECTORY_SEPARATOR : '');
|
||||
$config['allowed_types'] = 'gif|jpg|png';
|
||||
$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();
|
||||
|
||||
// Resize
|
||||
$config['image_library'] = 'gd2';
|
||||
$config['source_image'] = $data['full_path'];
|
||||
$config['maintain_ratio'] = TRUE;
|
||||
|
||||
$size = getimagesize($data['full_path']);
|
||||
|
||||
if($size[0] > $size[1]) {
|
||||
$config['height'] = $height;
|
||||
} else {
|
||||
$config['width'] = $width;
|
||||
}
|
||||
|
||||
$this->load->library('image_lib');
|
||||
$this->image_lib->initialize($config);
|
||||
$this->image_lib->resize();
|
||||
|
||||
$config['source_image'] = $config['upload_path'] . $config['file_name'];
|
||||
$config['maintain_ratio'] = FALSE;
|
||||
$config['height'] = $height;
|
||||
$config['width'] = $width;
|
||||
|
||||
$size = getimagesize($config['source_image']);
|
||||
|
||||
if($size[0] > $size[1]) {
|
||||
$config['x_axis'] = ($size[0] - $width) / 2;
|
||||
} else {
|
||||
$config['y_axis'] = ($size[1] - $height) / 2;
|
||||
}
|
||||
|
||||
$this->image_lib->clear();
|
||||
$this->image_lib->initialize($config);
|
||||
$this->image_lib->crop();
|
||||
|
||||
$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]);
|
||||
return '/f/' . $data['raw_name'];
|
||||
}
|
||||
}
|
||||
|
||||
public function uploadFileByContent($content, $original_name, $fullType, $fileSize, $userContent = true) {
|
||||
$target_dir = "files" . DIRECTORY_SEPARATOR . ($userContent ? 'userContent' . DIRECTORY_SEPARATOR : '');
|
||||
$filetype = pathinfo(basename($original_name), PATHINFO_EXTENSION);
|
||||
$target_file = $target_dir . $this->generateName() . '.' . $filetype;
|
||||
$name = explode('.' . $filetype, explode(DIRECTORY_SEPARATOR, $target_file)[1])[0];
|
||||
@@ -65,7 +121,7 @@ class FileModel extends CI_Model
|
||||
fwrite($fp, $content);
|
||||
fclose($fp);
|
||||
|
||||
$this->db->query('INSERT INTO files (name, original_name, type, size, path) VALUES (?, ?, ?, ?, ?)', [$name, $original_name, $fullType, $fileSize, $target_file]);
|
||||
$this->db->query('INSERT INTO files (name, original_name, type, size, path, isUserData) VALUES (?, ?, ?, ?, ?, ?)', [$name, $original_name, $fullType, $fileSize, $target_file, $userContent]);
|
||||
|
||||
return '/f/' . $name;
|
||||
}
|
||||
|
Reference in New Issue
Block a user