PHP class instance to JSON

You’re just about there. Take a look at get_object_vars in combination with json_encode and you’ll have everything you need. Doing: json_encode(get_object_vars($error)); should return exactly what you’re looking for. The comments brought up get_object_vars respect for visibility, so consider doing something like the following in your class: public function expose() { return get_object_vars($this); } And then … Read more

Encode / Decode .EXE into Base64

The problem was caused by: Get-Content without -raw splits the file into an array of lines thus destroying the code Text.Encoding interprets the binary code as text thus destroying the code Out-File is for text data, not binary code The correct approach is to use IO.File ReadAllBytes: $base64string = [Convert]::ToBase64String([IO.File]::ReadAllBytes($FileName)) and WriteAllBytes to decode: [IO.File]::WriteAllBytes($FileName, … Read more

PHP get pdf file from base64 encoded data string

Try this piece of code $pdf_base64 = “base64pdf.txt”; //Get File content from txt file $pdf_base64_handler = fopen($pdf_base64,’r’); $pdf_content = fread ($pdf_base64_handler,filesize($pdf_base64)); fclose ($pdf_base64_handler); //Decode pdf content $pdf_decoded = base64_decode ($pdf_content); //Write data back to pdf file $pdf = fopen (‘test.pdf’,’w’); fwrite ($pdf,$pdf_decoded); //close output file fclose ($pdf); echo ‘Done’;

Write Base64-encoded image to file

Assuming the image data is already in the format you want, you don’t need ImageIO at all – you just need to write the data to the file: // Note preferred way of declaring an array variable byte[] data = Base64.decodeBase64(crntImage); try (OutputStream stream = new FileOutputStream(“c:/decode/abc.bmp”)) { stream.write(data); } (I’m assuming you’re using Java … Read more

How to encode media in base64 given URL in Ruby

To encode a file: require ‘base64’ Base64.encode64(File.open(“file_path”, “rb”).read) To produce the file from the encoded string: require ‘base64’ encoded_string = Base64.encode64(File.open(“file_path”, “rb”).read) File.open(file_name_to_create, “wb”) do |file| file.write(Base64.decode64(encoded_string)) end

Encode string for URL (angular)

HttpParameterCodec : is a codec for encoding and decoding parameters in URLs( Used by HttpParams). If you need to encode Url you can use the below: encodeURI assumes that the input is a complete URI that might have some characters which need encoding in it. encodeURIComponent will encode everything with special meaning, so you use … Read more

C# Base64 String to JPEG Image

First, convert the base 64 string to an Image, then use the Image.Save method. To convert from base 64 string to Image: public Image Base64ToImage(string base64String) { // Convert base 64 string to byte[] byte[] imageBytes = Convert.FromBase64String(base64String); // Convert byte[] to Image using (var ms = new MemoryStream(imageBytes, 0, imageBytes.Length)) { Image image = … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)