<!DOCTYPE html>
<html ng-app>
<head>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" />
</head>
<body>
<div class="container">
<div class="hero">
<h1>Angular + requirejs + ng-flow</h1>
</div>
<div class="row">
<div ng-view="" class="col-md-12" ></div>
</div>
</div>
</body>
<script src="//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.9/require.min.js" data-main="main.js" ></script>
</html>
/* Styles go here */
/*jshint unused: vars */
require.config({
paths: {
angular: 'https://code.angularjs.org/1.3.0-beta.5/angular',
angularRoute: 'http://code.angularjs.org/1.2.17/angular-route',
ngFlow: 'http://flowjs.github.io/ng-flow/bower_components/ng-flow/dist/ng-flow-standalone'
},
shim: {
'angular' : {'exports' : 'angular'},
'angularRoute': ['angular'],
'ngFlow': ['angular']
},
priority: [
'jquery','angular'
]
});
//http://code.angularjs.org/1.2.1/docs/guide/bootstrap#overview_deferred-bootstrap
window.name = 'NG_DEFER_BOOTSTRAP!';
require([
'angular',
'angularRoute',
'app',
'ngFlow'
], function( angular, ngRoutes, app, ngFlow) {
'use strict';
/* jshint ignore:start */
var $html = angular.element(document.getElementsByTagName('html')[0]);
/* jshint ignore:end */
angular.element().ready(function() {
angular.resumeBootstrap([app.name]);
});
});
/*jshint unused: vars */
define([
'angular',
'controllers'
], function (angular, MainCtrl) {
'use strict';
return angular.module('App', [
'App.controller',
'ngRoute',
'flow'
])
.config(['$routeProvider', '$locationProvider', '$httpProvider', function ($routeProvider, $locationProvider, $httpProvider) {
$routeProvider
.when('/', {
templateUrl: 'main.html',
controller: 'MainCtrl',
})
.when('/upload', {
templateUrl: 'upload.html',
controller: 'UploadCtrl'
})
.otherwise({
redirectTo: '/'
});
}])
.config(['flowFactoryProvider', function (flowFactoryProvider) {
flowFactoryProvider.defaults = {
target: 'upload.php',
permanentErrors: [404, 500, 501],
maxChunkRetries: 1,
chunkRetryInterval: 5000,
simultaneousUploads: 4,
singleFile: false
};
flowFactoryProvider.on('catchAll', function (event) {
console.log('catchAll', arguments);
});
// Can be used with different implementations of Flow.js
// flowFactoryProvider.factory = fustyFlowFactory;
}]);
});
<h2>Welcome <span ng-bind="message"></span></h2>
<p>Testing ng-flow</p>
<a class="btn btn-primary" ng-href="#/upload">Go to uploads</a>
define(['angular'], function (angular) {
'use strict';
angular.module('App.controller', [])
.controller('MainCtrl', function ($scope) {
$scope.message = 'Visitor';
})
.controller('UploadCtrl', function ($scope, $flow) {
$scope.message = 'Uploader';
$flow.opts.target = 'another-upload-path.php';
});
});
<h2>Welcome <span ng-bind="message"></span></h2>
<div flow-init flow-file-added="!!{png:1,gif:1,jpg:1,jpeg:1}[$file.getExtension()]"
>
<p>Here you can upload your files</p>
<span class="btn btn-primary" flow-btn ng-href="#/upload">Upload!</span>
<div class="row">
<div class="col-md-3 col-xs-6" ng-repeat="file in $flow.files">
<img flow-img="file" class="img-responsive">
</div>
</div>
</div>
<?php
$tempDir = __DIR__ . DIRECTORY_SEPARATOR . 'temp';
if (!file_exists($tempDir)) {
mkdir($tempDir);
}
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$chunkDir = $tempDir . DIRECTORY_SEPARATOR . $_GET['flowIdentifier'];
$chunkFile = $chunkDir.'/chunk.part'.$_GET['flowChunkNumber'];
if (file_exists($chunkFile)) {
header("HTTP/1.0 200 Ok");
} else {
header("HTTP/1.0 404 Not Found");
}
}
// Just imitate that the file was stored.
echo json_encode([
'success' => true,
'files' => $_FILES,
'get' => $_GET,
'post' => $_POST,
//optional
'flowTotalSize' => isset($_FILES['file']) ? $_FILES['file']['size'] : $_GET['flowTotalSize'],
'flowIdentifier' => isset($_FILES['file']) ? $_FILES['file']['name'] . '-' . $_FILES['file']['size']
: $_GET['flowIdentifier'],
'flowFilename' => isset($_FILES['file']) ? $_FILES['file']['name'] : $_GET['flowFilename'],
'flowRelativePath' => isset($_FILES['file']) ? $_FILES['file']['tmp_name'] : $_GET['flowRelativePath']
]);
?>