0
    <?php
    $image = array(
        'name'  =>  'userfile',
        'id'    =>  'userfile',
        );

    $submit = array(
        'name'  => 'submit',
        'id'    => 'submit',
        'value' => 'Upload'
        );
?>
<?php echo form_open_multipart('upload/upload_image', 'id=upload_file'); ?> <!-- must autoload form helper for this -->
<?php echo form_upload($image); ?>
<?php echo form_submit($submit); ?>
<?php echo form_close(); ?>

这是视图文件夹中的 main.php

<?php
class Upload_model extends CI_Model{
    var $original_path;
    var $resized_path;
    var $thumbs_path;

    //initialize the path where you want to save your images
    function __construct(){
        parent::__construct();
        //return the full path of the directory
        //make sure these directories have read and write permessions
        $this->original_path = realpath(APPPATH.'../uploads/original');
        $this->resized_path = realpath(APPPATH.'../uploads/resized');
        $this->thumbs_path = realpath(APPPATH.'../uploads/thumbs');
    } 

    function do_upload(){
        $this->load->library('image_lib');
        $config = array(
        'allowed_types'     => 'jpg|jpeg|gif|png', //only accept these file types
        'max_size'          => 2048, //2MB max
        'upload_path'       => $this->original_path //upload directory
    );

        $this->load->library('upload', $config);
        $image_data = $this->upload->data(); //upload the image
        print_r($image_data);
        if($image_data){
            echo "uploaded";
        }else {echo "not upload";}

        //your desired config for the resize() function
        $config = array(
        'source_image'      => $image_data['full_path'], //path to the uploaded image
        'new_image'         => $this->resized_path, //path to
        'maintain_ratio'    => true,
        'width'             => 128,
        'height'            => 128
        );

        //this is the magic line that enables you generate multiple thumbnails
        //you have to call the initialize() function each time you call the resize()
        //otherwise it will not work and only generate one thumbnail
        $this->image_lib->initialize($config);
        $this->image_lib->resize();

        $config = array(
        'source_image'      => $image_data['full_path'],
        'new_image'         => $this->thumbs_path,
        'maintain_ratio'    => true,
        'width'             => 36,
        'height'            => 36
        );
        //here is the second thumbnail, notice the call for the initialize() function again
        $this->image_lib->initialize($config);
        $this->image_lib->resize();

    }
}

这是我的模型和控制器只加载 main.php 允许我选择图像单击提交然后控制器调用上面的模型来加载图像

问题是 --> 没有生成错误,但图像和拇指没有上传到目录,为什么?

4

0 回答 0