使用verot_upload类和dropzone.js上传codeigniter文件 [英] codeigniter file upload with verot_upload class and dropzone.js

查看:39
本文介绍了使用verot_upload类和dropzone.js上传codeigniter文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to get working my upload script.

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

I'm using CodeIgniter, dropzone.js and Verot_upload class

表格:

<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/upload方法

and /admin/images/upload method

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.

But not with verot_upload.

推荐答案

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

So the issue was that, I was trying to upload image as in example at the class initialization. if I initialize empty class and then use upload method everything works.

/**
 * 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();
        }
    }
}

这篇关于使用verot_upload类和dropzone.js上传codeigniter文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆