Giter Club home page Giter Club logo

angularjs-drag-drop-upload's Introduction

AngularJS Directive File Drag-n-Drop Upload

A drag and drop directive for easy file uploading.

AngularJS File Drag-n-Drop Upload

partial.html

<div
	drag-drop-upload
	clear-on-complete='true'
	action="main.contactImportAction"
	on-complete="uploadComplete(e, data)"
	on-error="uploadError(e, data)"
	on-progress="uploadProgress(progress, e, data)"></div>

controller.js

controllers.controller('MainCtrl', function($scope){
	$scope.main.contactImportAction = $scope.main.contactImportBase + 0;

	$scope.$watch('main.contactgroup', function() {
		var id = $scope.main.contactgroup.id || 0;
		$scope.main.contactImportAction = $scope.main.contactImportBase + id;
	}, true);
	
	$scope.uploadComplete = function(e, data) {
	}
	
	$scope.uploadProgress = function(progress, e, data) {
		l(progress);
	}
	
	$scope.uploadError = function(e, data) {
	}
});

controller.php (Laravel Framework)

<?php

class Contact_Controller extends Base_Controller
{
	
	public function post_import()
	{
		try {
			$allowed = array('csv', 'xls', 'xlsx');
			$file = Input::file('file');
			$file_ext = String::lower(File::extension($file['name']));
			$filename = Str::random(32) . uniqid() . '.' . $file_ext;

			if (is_array($file) && isset($file['error']) && $file['error'] == 0) {
				if(! in_array($file_ext, $allowed))
					throw new Exception("Invalid file type.");

				if (Input::upload('file', 'storage/work', $filename))
					return Response::json('{"status":"success"}');
			}

			throw new Exception('Could not upload file.');
		} catch (Exception $e) {
			return $e->getMessage();
		}
	}
}

ugly.php (From mini-upload-form.zip)

<?php

$allowed = array('png', 'jpg', 'gif','zip');

if(isset($_FILES['upl']) && $_FILES['upl']['error'] == 0){

	$extension = pathinfo($_FILES['upl']['name'], PATHINFO_EXTENSION);

	if(!in_array(strtolower($extension), $allowed)){
		echo '{"status":"error"}';
		exit;
	}

	if(move_uploaded_file($_FILES['upl']['tmp_name'], 'uploads/'.$_FILES['upl']['name'])){
		echo '{"status":"success"}';
		exit;
	}
}

echo '{"status":"error"}';
exit;

Bitdeli Badge

angularjs-drag-drop-upload's People

Contributors

bitdeli-chef avatar clouddueling avatar pawelniewie avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.