如何配置dropzone.js? [英] How do I configure dropzone.js?

查看:177
本文介绍了如何配置dropzone.js?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想配置dropzone来删除图像,我已经完成了`addRemoveLinks:true`我希望php代码删除该文件?如何获取要删除的文件的ID?我的第二个问题是如何通过dropzone上传视频?第三个问题是如何限制dropzone中文件的大小?



我尝试过:



I want to configure dropzone for removing images, I've done `addRemoveLinks: true` i want the php code to delete that file? How can I get the id of the file to delete? And my second question is how can I upload videos through dropzone? And the third question is how can I restrict size of the files in dropzone?

What I have tried:

if(typeof Dropzone != 'undefined')
{
	Dropzone.autoDiscover = false;
	var myDropzone = new Dropzone("#myDropzone", {
		url: "data/upload-file.php",
		maxFileSize: 50,
		acceptedFiles: ".pdf",
		addRemoveLinks: true,
		removedfile: function(file){
			var name = file.name;
			$.ajax({
				type: 'POST',
				url: 'delete.php',
				data: "id="+name,
				dataType: 'html'
			});
			var _ref;
			return(_ref = file.previewElement) != null
				? _ref.parentNode.removeChild(file.previewElement)
				: void 0;
		}
	};
}



这是delete.php:


and this is delete.php:

<?php
	$$dbHost = 'localhost';
	$dbUsername = 'root';
	$dbPassword = '';
	$dbName = 'newimg';

	//connect with the database
	$conn = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);

	if($mysqli->connect_errno){
		echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
	}

	$upload_dir = 'uploads';
	$targetPath = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . $upload_dir . DIRECTORY_SEPARATOR;
	unlink($targetPath.$_GET['id']);

	$obj=new DB();
	$sql = "DELETE FROM files WHERE id='".$_GET['id']."'";
	$retval = mysqli_query($obj->connection(),$sql);

	print_r("Successfully deleted.");
?>

推荐答案

.ajax({
类型:' POST'
url:' delete.php'
data: id = + name,
dataType:' html '
});
var _ref;
return (_ ref = file.previewElement)!= null
? _ref.parentNode.removeChild(file.previewElement)
void 0 ;
}
};
}
.ajax({ type: 'POST', url: 'delete.php', data: "id="+name, dataType: 'html' }); var _ref; return(_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0; } }; }



这是delete.php:


and this is delete.php:

<?php


dbHost = ' localhost ;
dbHost = 'localhost';


dbUsername = ' ;
dbUsername = 'root';


这篇关于如何配置dropzone.js?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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