本文整理汇总了PHP中upload::type方法的典型用法代码示例。如果您正苦于以下问题:PHP upload::type方法的具体用法?PHP upload::type怎么用?PHP upload::type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类upload
的用法示例。
在下文中一共展示了upload::type方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _save_img_bg
protected function _save_img_bg($image)
{
if (!upload::valid($image) or !upload::type($image, array('jpg', 'jpeg', 'png', 'gif'))) {
$this->session->set_flash('error_msg', 'Only upload file jpg , jpeg , png , gif');
url::redirect('admin_config');
} else {
$directory = DOCROOT . 'themes/client/styleSIC/index/pics/';
if ($file = upload::save($image, NULL, $directory)) {
$filename = 'bg_' . md5(rand(0, 999)) . time() . '.png';
Image::factory($file)->save($directory . $filename);
// Delete the temporary file
unlink($file);
return $filename;
}
return FALSE;
}
}
示例2: validate_this
protected function validate_this()
{
$input = Input::instance();
$fname = isset($_FILES[$this->name . '_file']) ? $this->name . '_file' : $this->name;
$file = isset($_FILES[$fname]) ? $_FILES[$fname] : NULL;
$already_uploaded = $input->post($this->name . '_path') ? TRUE : FALSE;
$this->was_validated = TRUE;
if ($this->required and empty($file['name']) and !$already_uploaded) {
if ($already_uploaded and is_file($input->post($this->name . '_path'))) {
unlink($input->post($this->name . '_path'));
}
$this->error = $this->required_msg;
return $this->error;
} elseif (!$this->required and !$input->post($this->name) and empty($file['name'])) {
return;
} else {
$allowed_types = Formo::splitby($this->allowed_types);
$time = time();
// this means we're good with the file uploaded already
if ($already_uploaded === TRUE and !$file['name']) {
$full_path = $input->post($this->name . '_path');
$path = array_pop(explode('/', $full_path));
$file_name = $input->post($this->name);
} elseif ($file['name']) {
// delete old entry
if ($already_uploaded) {
$full_path = $input->post($this->name . '_path');
$path = array_pop(preg_split('/\\//', $full_path));
$file_name = $input->post($this->name);
if (is_file($full_path)) {
unlink($full_path);
}
}
// start validating
if (!upload::required($file)) {
return $this->error = Kohana::lang('formo.invalidfile');
}
if (!upload::size($file, array($this->max_size))) {
return $this->error = Kohana::lang('formo.too_large') . ' (' . $this->max_size . ')';
}
if (!upload::type($file, $allowed_types)) {
return $this->error = Kohana::lang('formo.invalid_type');
}
$full_path = upload::save($fname, $time . $file['name'], DOCROOT . $this->upload_path, 0777);
$path = array_pop(preg_split('/\\//', $full_path));
$file_name = $file['name'];
}
// fill $this->data with appropriate info
$this->data['orig_name'] = $file_name;
$this->data['file_name'] = end(preg_split('/\\//', $full_path));
$this->data['path'] = preg_replace('/\\/' . $this->data['file_name'] . '/', '', $full_path);
$this->data['full_path'] = $full_path;
$this->data['file_ext'] = strtolower(substr(strrchr($file_name, '.'), 1));
$this->data['file_type'] = reset(Kohana::config('mimes.' . $this->data['file_ext']));
$this->data['bytes'] = filesize($full_path);
$this->data['file_size'] = round(filesize($full_path) / 1024, 2);
$this->data['time'] = $time;
if ($isize = getimagesize($full_path)) {
$this->data['is_image'] = 1;
$this->data['image_width'] = $isize[0];
$this->data['image_height'] = $isize[1];
$this->data['image_size_str'] = $isize[3];
} else {
$this->data['is_image'] = 0;
$this->data['image_width'] = NULL;
$this->data['image_height'] = NULL;
$this->data['image_size_str'] = NULL;
}
$this->value = $this->data;
// create the extra stuff for saving past, accepted uploads and unvalidated forms
$this->type = 'text';
$this->_was_file = TRUE;
$this->add_class($this->file_link_class);
$this->value = $file_name;
$this->readOnly = 'readOnly';
$this->onClick = 'file_replace(\'' . $this->id . '\')';
$oldclose = $this->element_close;
$class = !empty($this->class) ? ' class="' . preg_replace('/ *' . $this->file_link_class . '/', '', $this->class) . '"' : '';
$this->str = '<input type="text" name="' . $this->name . '" value="' . $this->value . '"' . Formo::quicktagss($this->_find_tags()) . ' />' . '<script type="text/javascript">' . "\n" . 'function file_replace(id){' . "\n" . 'var txt = document.getElementById(id);' . "\n" . 'var file = document.getElementById(id+"_file");' . "\n" . 'txt.style.display = "none";' . "\n" . 'file.style.display = "inline";' . "\n" . '}' . "\n" . '</script>' . "\n" . '<input type="hidden" name="' . $this->name . '_path" id="' . $this->id . '_path" value="' . $full_path . '" />' . "\n" . '<input type="file" name="' . $this->name . '_file" id="' . $this->id . '_file"' . $class . ' style="display:none"/>' . "\n" . $oldclose;
}
}
示例3: _save_img_s3
protected function _save_img_s3($image)
{
require Kohana::find_file('views/aws', 'init');
if (!upload::valid($image) or !upload::type($image, array('jpg', 'jpeg', 'png', 'gif'))) {
$this->session->set_flash('error_msg', 'Only upload file jpg , jpeg , png , gif');
///url::redirect('admin_config');
//die();
return FALSE;
} else {
$name = $image['name'];
$size = $image['size'];
$tmp = $image['tmp_name'];
$actual_image_name = 'ans_' . md5($image['name'] . time()) . "." . 'png';
try {
// Upload data.
$result = $s3Client->putObject(array('Bucket' => $s3_bucket, 'Key' => 'answer/' . $actual_image_name, 'SourceFile' => $this->s3_resize($tmp, 593, 539), 'ACL' => 'public-read', 'ContentType' => 'image/png'));
return $actual_image_name;
} catch (S3Exception $e) {
return FALSE;
}
return FALSE;
}
}
示例4: _save_img_courses
protected function _save_img_courses($image, $hd_id = '')
{
if (!upload::valid($image) or !upload::type($image, array('jpg', 'jpeg', 'png', 'gif'))) {
$this->session->set_flash('error_msg', 'Only upload file jpg , jpeg , png , gif');
if ($hd_id) {
url::redirect('admin_test/edit/' . $hd_id);
} else {
url::redirect('admin_test/create');
}
} else {
$directory = DOCROOT . 'uploads/courses_img/';
if ($file = upload::save($image, NULL, $directory)) {
$filename = md5(rand(0, 999)) . '.png';
Image::factory($file)->resize(200, 200, Image::AUTO)->save($directory . $filename);
// Delete the temporary file
unlink($file);
return $filename;
}
return FALSE;
}
}