【问题标题】:codeigniter file upload with verot_upload class and dropzone.js使用 verot_upload 类和 dropzone.js 上传 codeigniter 文件
【发布时间】:2014-06-05 21:35:55
【问题描述】:

我正在尝试使用我的上传脚本。

我正在使用 CodeIgniter、dropzone.js 和 Verot_upload 类

表格:

<form action="/admin/images/upload" 
      enctype="multipart/form-data" method="post"
      class="dropzone"
      id="my-awesome-dropzone"></form>

<script src="/skin/js/dropzone.js"></script>

和/admin/images/上传方法

public function upload()
{
    $data = array();
    $this->load->library('verot_upload');
    if ($this->authentication->is_loggedin())
    {
        if (!empty($_FILES))
        {
            //                $tempFile = $_FILES['file']['tmp_name'];
            $foo = new Verot_upload($_FILES['file']);

            if ($foo->uploaded)
            {
                // save uploaded image with no changes
                $foo->Process('./media/test/');

            }
        }

    } else
    {
        redirect('/admin/login/', 'refresh');
    }
}

它适用于常规样式:

function upload()
{

    if (!empty($_FILES))
    {
        $tempFile = $_FILES['file']['tmp_name'];
        $targetPath = $_SERVER['DOCUMENT_ROOT'] . '/uploads/';
        $targetFile = $targetPath . $_FILES['file']['name'];
        move_uploaded_file($tempFile, $targetFile);
        // save data in database (if you like!)
    }
}

但不是使用 verot_upload。

【问题讨论】:

    标签: javascript php codeigniter


    【解决方案1】:

    所以问题是,我试图在类初始化时上传图像,例如。 如果我初始化空类然后使用上传方法一切正常。

    /**
     * Method for uploading Images from dropdown form.
     *
     * @param $size
     * @param $path
     * @param $file
     */
    public function upload_image($size, $path, $file)
    {
        $this->load->library('verot_upload');
        $foo = new Verot_upload();
    
        $foo->upload($file);
        if ($foo->uploaded)
        {
            $foo->image_resize = true;
            $foo->image_x = $size;
            $foo->image_ratio_y = true;
            $foo->Process($path);
            if ($foo->processed)
            {
                $new_path = substr($foo->file_dst_pathname,1);
                $this
                    ->db
                    ->set('date_created', 'NOW()', false)
                    ->set('path', $new_path, true)
                    ->insert('wysiwyg_img_uploads');
    
                $foo->Clean();
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-10-10
      • 2013-12-21
      • 2013-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-16
      相关资源
      最近更新 更多