Codeigniter文件上传与verot_upload类和dropzone.js


codeigniter file upload with verot_upload class and dropzone.js

我想让我的上传脚本工作。

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

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

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

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