使用verot_upload类和dropzone.js上传codeigniter文件

时间:2014-06-05 21:35:56

标签: javascript php codeigniter

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

我使用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。

1 个答案:

答案 0 :(得分:0)

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

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