0

I have started learning PHP. I am using file path in many files. I want instead use it define in config file and use that variable in all required files. currently I have used it like below in my file.

function base64ToImageProfile($base64_code){

    $img_base64 = $base64_code;
    //replace data:image/jpeg tag from base64
    $img_base64 = str_replace('data:image/jpeg;base64,', '', $img_base64);

     //replace data:image/png tag from base64
    $img_base64 = str_replace('data:image/png;base64,', '', $img_base64);

     //replace space with  + from base64
    $img_base64 = str_replace(' ', '+', $img_base64);

     //decode base64 to image object
    $decode_img = base64_decode($img_base64);

    if (!$decode_img) {
      return 'error';
    }
    //create path for image
    $file_path=  'userImage/'.uniqid().'.png';

    $success=file_put_contents($file_path,$decode_img);
     //saves decoded image to specified path
    if ($success) {

      $file_path = 'www.example.com/myfolder/'.$file_path;
    }

    return $success ? $file_path:'error';    

}

I want to use the variable for my url located in it from config file. How can I do it?

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141

0 Answers0