Skip to content

Instantly share code, notes, and snippets.

@kevinold
Forked from jchaney01/UtilityController.php
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinold/6a12752936a80ebbddb6 to your computer and use it in GitHub Desktop.
Save kevinold/6a12752936a80ebbddb6 to your computer and use it in GitHub Desktop.

Work in progress

The goal is to be able to create multiple image uploaders with editors per page with little HTML markup.

App.directive('caUploaderInput', ["uploadConfig",'$log','$compile',function(uploadConfig,$log,$compile) {
var directive = {
restrict: 'A',
transclude:false,
replace:true,
scope:{
prefill:"@"
},
link: function(scope, element, attrs, ctrl) {
$log.debug("Init caUploader");
if(scope.prefill){
scope.fileName=scope.prefill;
}
var setFileName = function(name){
scope.fileName=name.name;
scope.orgFileName=name.origName;
scope.$apply();
};
$(element.find("input").first()).uploadify({
'uploader' : "/upload",
'swf' : "/js/uploadify/uploadify.swf",
'cancelImg' : '',
'folder' : "/images/uploads",
'queueID' : "queue",
'auto' : true,
'multi' : false,
'buttonImg' : '',
'width' : '117',
'height' : '34',
'onSelect' : function(e, q, f) {
$log.debug("On select");
},
'onError' : function (event,ID,fileObj,errorObj) {
alert(errorObj.type + ' Error: ' + errorObj.info);
},
'onUploadSuccess' : function(file,data,response) {
setFileName($.parseJSON(data));
}
});
}
};
return directive;
}]);
<div ca-uploader-input prefill="image on disc">
<input id="imageOne">
<input name="imageOne" type="text" ng-model="fileName">
<div ng-show="fileName" style="clear: both">
shows editor
</div>
</div>
class UtilityController extends BaseController {
public function upload()
{
$file = Input::file('Filedata');
$name = Date("now").'-'.$file->getClientOriginalName();
$uploadSuccess = $file->move(public_path().'/uploads',$name);
if( $uploadSuccess ) {
return Response::json(array(
"status"=>"200",
"name"=>$name,
"origName"=>$file->getClientOriginalName()
),200);
} else {
return Response::json('error', 400);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment