如何在文件扩展名之前插入“_thumb”? 例如123.jpg到123_thumb.jpg
请回答我的问题,已经3天我找不到合适的方式..谢谢
这是我的观点:
#include <memory>
int main()
{
{
RigidBody b;
std::unique_ptr<Adaptor> a{Adaptor::adapt(b)};
a->setPosition(15.);
a->getPosition();
}
{
RigidBody const b;
std::unique_ptr<const Adaptor> a{Adaptor::adapt(b)};
a->setPosition(15.); // error: passing ‘const Adaptor’ as ‘this’ argument discards qualifiers
a->getPosition();
}
}
这是我的控制者:
<div class="row service-box margin-bottom-40">
<!-- carousel -->
<div class="col-md-4">
<div class="carousel slide">
<?php
$reports_slide = $this->m_dashboard->report_slide();
foreach ($reports_slide as $row) {
echo '
<img width="100%" src="' . base_url() . 'img/report/thumbs/' . $row->report_img . '" class="mySlides">
';
} ?>
<script>
var slideIndex = 0;
carousel();
function carousel() {
var i;
var x = document.getElementsByClassName("mySlides");
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
slideIndex++;
if (slideIndex > x.length) {slideIndex = 1}
x[slideIndex-1].style.display = "block";
setTimeout(carousel, 2000); // Change image every 2 seconds
}
</script>
</div>
</div>
这是我的模特:
public function add_report()
{
$field_img = "img";
$field_thumb = "thumb";
$field_pdf = "pdf";
// this is for form field 1 which is an image....
$config['upload_path'] = '../img/report/';
$config['allowed_types'] = 'gif|jpg|png|pdf';
$config['max_size'] = '1024';
$config['remove_spaces'] = TRUE;
$config['overwrite'] = TRUE;
$this->load->view('includes/header');
$this->load->view('includes/menu');
if (isset($_POST['submit'])) {
if (isset($_FILES['img']['name']) && is_uploaded_file($_FILES['img']['tmp_name'])){
$config['file_name'] = '_image_'.$_POST['id_company'].'_'.$_POST['report_title'];
$this->upload->initialize($config);
$this->upload->do_upload($field_img);
$file_name = $this->upload->data();
$file_img = $file_name['file_name'];
$config = array(
'image_library' => 'gd2',
'source_image' => $file_name['full_path'],
'new_image' => '../img/report/thumbs/',
'create_thumb' => TRUE,
'maintain_ratio' => FALSE,
'width' => 827,
'height' => 1170,
);
$this->image_lib->clear();
$this->image_lib->initialize($config);
$this->image_lib->resize();
}
}
}
}
答案 0 :(得分:0)
英语不是我的母语,对不起。
对于拇指的设置à新名称,您只需更改此配置
'new_image' => '../img/report/thumbs/'
执行此操作时,您将获得有关文件
的大量信息$file_name = $this->upload->data();
如果你喜欢Ci :: Upload,你会看到函数数据返回
public function data($index = NULL)
{
$data = array(
'file_name' => $this->file_name,
'file_type' => $this->file_type,
'file_path' => $this->upload_path,
'full_path' => $this->upload_path.$this->file_name,
'raw_name' => substr($this->file_name, 0, -strlen($this->file_ext)),
'orig_name' => $this->orig_name,
'client_name' => $this->client_name,
'file_ext' => $this->file_ext,
'file_size' => $this->file_size,
'is_image' => $this->is_image(),
'image_width' => $this->image_width,
'image_height' => $this->image_height,
'image_type' => $this->image_type,
'image_size_str' => $this->image_size_str,
);
if ( ! empty($index))
{
return isset($data[$index]) ? $data[$index] : NULL;
}
return $data;
}
在你的情况下,你感兴趣的是什么
'raw_name' => substr($this->file_name, 0, -strlen($this->file_ext)),
哪个给:
$config = array(
'image_library' => 'gd2',
'source_image' => $file_name['full_path'],
'new_image' => "../img/report/thumbs/".$file_name['raw_name']."_thumb.".$file_name['file_ext'],
'create_thumb' => TRUE,
'maintain_ratio' => FALSE,
'width' => 827,
'height' => 1170,
);
答案 1 :(得分:0)
我使用此扩展程序:http://www.matmoo.com/digital-dribble/codeigniter/image_moo/
它比Codeigniter自己的库更成功。特别是当我想保存多种尺寸的缩略图时。