本文整理汇总了PHP中SiteHelpers::cropImage方法的典型用法代码示例。如果您正苦于以下问题:PHP SiteHelpers::cropImage方法的具体用法?PHP SiteHelpers::cropImage怎么用?PHP SiteHelpers::cropImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SiteHelpers
的用法示例。
在下文中一共展示了SiteHelpers::cropImage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validatePost
function validatePost($table)
{
$str = $this->info['config']['forms'];
$data = array();
foreach ($str as $f) {
$field = $f['field'];
if ($f['view'] == 1) {
if ($f['type'] == 'textarea_editor' || $f['type'] == 'textarea') {
$content = isset($_POST[$field]) ? $_POST[$field] : '';
/* Use this filter for html sanity
$data[$field] = Purifier::clean($content);
*/
$data[$field] = $content;
} else {
SiteHelpers::globalXssClean();
if (!is_null(Input::get($field))) {
$data[$field] = Input::get($field);
}
// if post is file or image
if ($f['type'] == 'file') {
if (!is_null(Input::file($field))) {
$file = Input::file($field);
$destinationPath = './' . str_replace('.', '', $f['option']['path_to_upload']);
$filename = $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension();
//if you need extension of the file
$rand = rand(1000, 100000000);
$newfilename = strtotime(date('Y-m-d H:i:s')) . '-' . $rand . '.' . $extension;
$uploadSuccess = Input::file($field)->move($destinationPath, $newfilename);
if ($f['option']['resize_width'] != '0' && $f['option']['resize_width'] != '') {
if ($f['option']['resize_height'] == 0) {
$f['option']['resize_height'] = $f['option']['resize_width'];
}
$orgFile = $destinationPath . '/' . $newfilename;
SiteHelpers::cropImage($f['option']['resize_width'], $f['option']['resize_height'], $orgFile, $extension, $orgFile);
}
if ($uploadSuccess) {
$data[$field] = $newfilename;
}
} else {
unset($data[$field]);
}
}
// if post is checkbox
if ($f['type'] == 'checkbox') {
if (!is_null(Input::get($field))) {
$data[$field] = implode(",", Input::get($field));
}
}
// if post is date
if ($f['type'] == 'date') {
$data[$field] = date("Y-m-d", strtotime(Input::get($field)));
}
// if post is seelct multiple
if ($f['type'] == 'select') {
if (isset($f['option']['is_multiple']) && $f['option']['is_multiple'] == 1) {
$data[$field] = implode(",", Input::get($field));
}
}
}
}
}
$global = isset($this->access['is_global']) ? $this->access['is_global'] : 0;
if ($global == 0) {
$data['entry_by'] = Session::get('uid');
}
return $data;
}
示例2: validatePost
function validatePost($table)
{
$request = new Request();
/// return json_encode($_POST);
$str = $this->info['config']['forms'];
$data = array();
foreach ($str as $f) {
$field = $f['field'];
if ($f['view'] == 1) {
if ($f['type'] == 'textarea_editor' || $f['type'] == 'textarea') {
$content = isset($_POST[$field]) ? $_POST[$field] : '';
$data[$field] = $content;
} else {
if (isset($_POST[$field])) {
$data[$field] = $_POST[$field];
}
// if post is file or image
if ($f['type'] == 'file') {
$files = '';
if (isset($f['option']['image_multiple']) && $f['option']['image_multiple'] == 1) {
if (isset($_POST['curr' . $field])) {
$curr = '';
for ($i = 0; $i < count($_POST['curr' . $field]); $i++) {
$files .= $_POST['curr' . $field][$i] . ',';
}
}
if (!is_null(Input::file($field))) {
$destinationPath = '.' . $f['option']['path_to_upload'];
foreach ($_FILES[$field]['tmp_name'] as $key => $tmp_name) {
$file_name = $_FILES[$field]['name'][$key];
$file_tmp = $_FILES[$field]['tmp_name'][$key];
if ($file_name != '') {
move_uploaded_file($file_tmp, $destinationPath . '/' . $file_name);
$files .= $file_name . ',';
}
}
if ($files != '') {
$files = substr($files, 0, strlen($files) - 1);
}
}
$data[$field] = $files;
} else {
if (!is_null(Input::file($field))) {
$file = Input::file($field);
$destinationPath = '.' . $f['option']['path_to_upload'];
$filename = $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension();
//if you need extension of the file
$rand = rand(1000, 100000000);
$newfilename = strtotime(date('Y-m-d H:i:s')) . '-' . $rand . '.' . $extension;
$uploadSuccess = $file->move($destinationPath, $newfilename);
if ($f['option']['resize_width'] != '0' && $f['option']['resize_width'] != '') {
if ($f['option']['resize_height'] == 0) {
$f['option']['resize_height'] = $f['option']['resize_width'];
}
$orgFile = $destinationPath . '/' . $newfilename;
\SiteHelpers::cropImage($f['option']['resize_width'], $f['option']['resize_height'], $orgFile, $extension, $orgFile);
}
if ($uploadSuccess) {
$data[$field] = $newfilename;
}
} else {
unset($data[$field]);
}
}
}
// if post is checkbox
if ($f['type'] == 'checkbox') {
if (!is_null($_POST[$field])) {
$data[$field] = implode(",", $_POST[$field]);
}
}
// if post is date
if ($f['type'] == 'date') {
$data[$field] = date("Y-m-d", strtotime($request->input($field)));
}
// if post is seelct multiple
if ($f['type'] == 'select') {
//echo '<pre>'; print_r( $_POST[$field] ); echo '</pre>';
if (isset($f['option']['select_multiple']) && $f['option']['select_multiple'] == 1) {
$multival = is_array($_POST[$field]) ? implode(",", $_POST[$field]) : $_POST[$field];
$data[$field] = $multival;
} else {
$data[$field] = $_POST[$field];
}
}
}
}
}
$global = isset($this->access['is_global']) ? $this->access['is_global'] : 0;
if ($global == 0) {
$data['entry_by'] = \Session::get('uid');
}
return $data;
}
示例3: validatePost
function validatePost($table = '')
{
$str = $this->info['config']['forms'];
$data = array();
foreach ($str as $f) {
$field = $f['field'];
if ($f['view'] == 1) {
if (!is_null($this->input->get($field, true))) {
$data[$field] = $this->input->get($field, true);
}
switch ($f['type']) {
case 'textarea_editor':
case 'textarea':
$content = $this->input->get_post($field) ? $this->input->get_post($field) : '';
$data[$field] = $content;
break;
case 'file':
$this->load->library('upload');
$destinationPath = "./" . $f['option']['path_to_upload'];
$config['upload_path'] = $destinationPath;
$config['allowed_types'] = 'gif|jpg|png';
$this->upload->initialize($config);
if ($this->upload->do_upload($field)) {
$file_data = $this->upload->data();
$filename = $file_data['file_name'];
$extension = $file_data['file_ext'];
//if you need extension of the file
if ($f['option']['resize_width'] != '0' && $f['option']['resize_width'] != '') {
if ($f['option']['resize_height'] == 0) {
$f['option']['resize_height'] = $f['option']['resize_width'];
}
$origFile = $destinationPath . '/' . $filename;
SiteHelpers::cropImage($f['option']['resize_width'], $f['option']['resize_height'], $orgFile, $extension, $orgFile);
}
$data[$field] = $filename;
} else {
unset($data[$field]);
}
break;
case 'checkbox':
if (!is_null($this->input->get($field, true))) {
$data[$field] = implode(",", $this->input->get_post($field, true));
}
break;
case 'date':
$data[$field] = date("Y-m-d", strtotime($this->input->get_post($field, true)));
break;
case 'select':
if (isset($f['option']['is_multiple']) && $f['option']['is_multiple'] == 1) {
$data[$field] = implode(",", $this->input->get_post($field, true));
} else {
$data[$field] = $this->input->get_post($field, true);
}
break;
case 'text':
default:
$data[$field] = $this->input->get_post($field, true);
break;
}
}
}
$global = isset($this->access['is_global']) ? $this->access['is_global'] : 0;
if ($global == 0) {
$data['entry_by'] = $this->session->userdata('uid');
}
return $data;
}