php - PHPSlim + angular-file-upload -


i use angular-upload-file server side built php slim framework. on fileuploader config have :

$scope.uploader = new fileuploader({     url: 'upload/upload.php' }); 

then in backend, related wiki :

 if ( !empty( $_files ) ) {     $temppath = $_files[ 'file' ][ 'tmp_name' ];     $uploadpath = dirname( __file__ ) . directory_separator . 'uploads' . directory_separator . $_files[ 'file' ][ 'name' ];     move_uploaded_file( $temppath, $uploadpath );     $answer = array( 'answer' => 'file transfer completed' );     $json = json_encode($answer);     echo $json; } else {     echo 'no files'; } 

the problem when put code without using php slim works fine, when try wrap phpslim , get request instead of post:

enter image description here

with such code :

 $scope.uploader = new fileuploader({     url: 'api/upload/img' }); 

and api :

$app->post('/upload/img', function(){ if ( !empty( $_files ) ) {     $temppath = $_files[ 'file' ][ 'tmp_name' ];     $uploadpath = dirname( __file__ ) . directory_separator . 'uploads' . directory_separator . $_files[ 'file' ][ 'name' ];     move_uploaded_file( $temppath, $uploadpath );     $answer = array( 'answer' => 'file transfer completed' );     $json = json_encode($answer);     echo $json; } else {     echo 'no files'; } 

});

i try figure out issue come from, server or client side ? tried use similar plugin ng-file-upload have same problem, think should phpslim not sure.

i need use phpslim because use middleware required authentication requests.

thanks in advance,

first need call right address api:

var uploader = $scope.uploader = new fileuploader({   url: 'api/path/upload' }); 

in backend need

 $app->post('/upload', function() {       if ( !empty( $_files ) ) {...        }  }) 

if have problem message response need formatted build on way:

    $answer = array(           'status' => 'success',           'message' => 'file transfer completed',         ); ...   echoresponse(200, $answer); ...     function echoresponse($status_code, $response) {         global $app;         $app->status($status_code);         $app->contenttype('application/json');         echo json_encode($response, json_numeric_check);     } 

also create , set write folder permission for

$uploadpath = dirname( __file__ ) . directory_separator . 'uploads' . directory_separator . $_files[ 'file' ][ 'name' ]; 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -