图像调整大小并更改图像名称|笨

时间:2016-04-06 04:59:42

标签: php codeigniter image-uploading shopping-cart

这是我收到错误的代码,其他一切都很好,只有图像没有存储在文件夹中,但图像名称存储在数据库中。

<?php
function add_product()
{
    if($this->input->post('action')=='')
    {
        $this->load->view('admin/add_product');
    }
    else
    {
        $this->form_validation->set_rules('title', 'product name', 'trim|required|min_length[3]|max_length[30]');
        $this->form_validation->set_rules('price', 'price', 'trim|required|numeric');
        $this->form_validation->set_rules('stock', 'stock', 'trim|required|numeric');
        $this->form_validation->set_rules('cat_id', 'category', 'trim|required');
        $this->form_validation->set_rules('desc', 'description', 'trim|required');
        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view("admin/add_product");
        }
        else
        {
            //Here the image manipulation is starting
            $id = $this->admin_model->add_product($this->input->post());
            include("lib/imageManipulation.php");
            include("lib/resize-class.php");
            $type       =   substr(strtolower($_FILES['file']['name']),-4);
            $img_name   =   substr($this->input->post('title'),0,20);
            $img_name   =   str_replace(" ","_",$img_name) ."_". $id;
            $big_image  =   "images/uploads/".$img_name."".$type;
            $med_image  =   "images/uploads/".$img_name."_med".$type;
            $thumbnail  =   "images/uploads/".$img_name."_small".$type;
            copy($_FILES['file'],$big_image);
            $resizeObj = new resize($big_image);
            $resizeObj -> resizeImage(75, 75, 'auto');
            $resizeObj -> saveImage($thumbnail, 100);
            $resizeObj = new resize($big_image);
            $resizeObj -> resizeImage(220, 220, 'auto');
            $resizeObj -> saveImage($med_image, 100);
            $resizeObj = new resize($big_image);
            $resizeObj -> resizeImage(300, 300, 'auto');
            $resizeObj -> saveImage($big_image, 100);
            $this->admin_model->update_image_links($big_image,$med_image,$thumbnail,$id);
            $url = base_url()."index.php/admin/products";
            header("Location:$url");
            exit();
        }
    }
}
?>

如果有人可以在不调整图像大小的情况下执行此操作,那么也非常感谢!

0 个答案:

没有答案