[英]codeigniter file upload with verot_upload class and dropzone.js
I'm trying to get working my upload script. 我正在尝试使用我的上传脚本。
I'm using CodeIgniter, dropzone.js and Verot_upload class 我正在使用CodeIgniter,dropzone.js和Verot_upload类
form: 形成:
<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>
and /admin/images/upload method 和/ 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');
}
}
it works with regular style: 它可以使用常规样式:
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!)
}
}
But not with verot_upload. 但不是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();
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.