javascript - Uploading both original and resized images with ng-file-upload -




i'm trying app both save in server resized image , original file.

this i've tried far:

html:

<a ng-model="originalpic"     ngf-select="uploadphototest($file)"     ngf-resize="{width: 1170, type: 'image/jpeg'}"     ngf-resize-if="$width > 1000"    ngf-model-options="{updateon: 'change drop paste'}"     ngf-fix-orientation="true">       upload image </a> 

js:

$scope.uploadphototest = function (file) {   $scope.fileext = file.name.substring(file.name.lastindexof('.'), file.name.length);   $scope.uniqueportrait = $scope.fairnameonly + "-" + moment().format('dd-mm-yyyy-hh-mm-ss') + $scope.fileext;    upload.imagedimensions(file).then(function(dimensions){     if (dimensions.width < 1170){       $scope.sizeerror = true;      }else{        fileor = $scope.originalpic;        upload.upload({         url: 'uploadtest.php',         data: {           file: file,           name: upload.rename(file, $scope.uniqueportrait),           fileor: fileor,         }       }).then(function (resp) {          ...       });     };   }); }; 

and php:

<?php     $filename = $_files['file']['name'];     $destination = '/home/clients/cc5399b00bc00f15dc81742a0369c7b8/discovery/register/uploadstest/' . $filename;     move_uploaded_file( $_files['file']['tmp_name'] , $destination );      $filenameor = "original".$_files['fileor']['name'];     $destinationor = '/home/clients/cc5399b00bc00f15dc81742a0369c7b8/discovery/register/uploadstest/' . $filenameor;     move_uploaded_file( $_files['fileor']['tmp_name'] , $destinationor );  ?> 

so far going through uploading resized one, original 1 seems not pass model function, model comes undefined in console...

what missing?

you use upload.resize service of library. not use ngf-resize andgf-resize-if in html resize file in js. like:

html:

<a ng-model="originalpic"     ngf-select="uploadphototest($file)"     ngf-model-options="{updateon: 'change drop paste'}"     ngf-fix-orientation="true">       upload image </a> 

js

$scope.uploadphototest = function (file) {   $scope.fileext = file.name.substring(file.name.lastindexof('.'), file.name.length);   $scope.uniqueportrait = $scope.fairnameonly + "-" + moment().format('dd-mm-yyyy-hh-mm-ss') + $scope.fileext;    upload.imagedimensions(file).then(function(dimensions){     if (dimensions.width < 1170){         $scope.sizeerror = true;     } else if(dimensions.width > 1000){         var resizeoptions = {             width: 1170         };          upload.resize(file, resizeoptions).then(function(resizedfile) {             uploadfile(file, resizedfile);         });     } else {         uploadfile(file, file);     }   }); };  function uploadfile(originalfile, resizedfile) {     upload.upload({         url: 'uploadtest.php',         data: {             file: resizedfile,             fileor: upload.rename(file, $scope.uniqueportrait), //this returns file         }     }).then(function (resp) {         ...     }); } 

here's fiddle of similar: jsfiddle





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -