如何在文件擴展名之前插入「_thumb」? 例如123.jpg到123_thumb.jpg如何在文件擴展名之前插入「_thumb」
請回答我的問題,這是3天,我沒有找到合適的方式..謝謝
這是我的看法:
<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();
}
}
}
}
,這是我的模型:
public function report_slide()
{
//report
$this->db->select('a.*, b.category_name, c.co_abbreviated_name, d.country_name, e.language, f.report_type, g.year, h.type');
$this->db->from('rc_report a, rc_category b, rc_company c, rc_country d, rc_language e, rc_report_type f, rc_year g, rc_gri h');
$this->db->where('b.id_category = a.id_category');
$this->db->where('c.id_company = a.id_company');
$this->db->where('d.id_country = a.id_country');
$this->db->where('e.id_language = a.id_language');
$this->db->where('f.id_report_type = a.id_report_type');
$this->db->where('g.id_year = a.id_year');
$this->db->where('h.id_gri = a.id_gri');
$this->db->order_by('g.year','desc');
$this->db->limit(5);
$query_report = $this->db->get();
$result_array=$query_report->result();
return $result_array;
}
您是否檢查過這個網址http://stackoverflow.com/questions/2429611/regex-how-to-insert-string-before-file-extension –
如果您確定文件名中只有一個點,那麼你可以使用'str_replace()' – RST
在哪裏應該把這種語法,在視圖或控制器? –