base64_decode on audio file in PHP - php

When trying to get base64 encoded data from IOS through API and decoding it in server giving empty response for large files. Means its working fine for audio files less than 5MB only. I can't even identify this problem is happening while encoding in app side or while decoding in server side.
So how can I fix this problem?
Please help me to solve this. All your answers will be appreciated. Thank you.

file_put_contents('audio.mp3', base64_decode($data));

Related

PHP base64 encode a PDF file - Timing out

So I am using a Web Service and I am generating an XML file, I need to send across PDF files as base64 encode instead of just passing the URL.
The XML is processing around 500 requests and the way I am encoding the PDF is as follows:-
$filesrc = get_field('property_pdf');
$b64Doc = chunk_split(base64_encode(file_get_contents($filesrc)));
However, when I am doing this the process ends up just timing out, is there better way of encoding a PDF or am I not doing it correctly?
Note: It processes all 500 properties in less than 5 seconds before adding the above code to the XML generation.
Any help would be much appreciated.

Standara way for passing image from android to php server

I'm trying to pass an image from Android application to php server.
I searched about that, I have two ways:
Sending by Multipart
Encode to Base64
I'm using Volley, I know about both but I don't know which is better for implementation.
Can you tell me which is standard and better?
Do not go with the base64 string since it may give you crash if it exceeds the limit. Better option to use the Multipart, it is reliable and safe.

Upload images to the database and retrieve upon user request in Android (via PHP)

I am trying to upload an image to the MySQL database in android(via PHP) and retrieve it upon user request. I searched everywhere but I still couldn't find an answer on how to do it. I am new to Android and would really appreciate it if you could help me. Please tell me a method to upload images to MySQL and retrieve only the requested images. I don't mind using URLs too. Thank you
I have done this using java. I have not much knowledge of PHP so I am providing you my java code to you. I hope you are able to convert it in PHP.
I am converting image to byte[] and passing byte[] in json string using http request to my RESTful web service. In service I am storing whole array in mysql blob. below is my code to store image in blob using JDBC connection.
final PreparedStatement ps = connection.prepareStatement(query);
ps.setBinaryStream(1, new ByteArrayInputStream(ImageArray, ImageArray.length);
ps.executeUpdate();
I hope this will help you.

createimagefromstring gives invalid chunk type

Did not find any solutions to my problem .. so here we go..
I have a SLIM webservice, which supports uploading a report containing one or more base64 encoded images.
All data i receive in my webservice functions are json encoded and therefore i decode everything before handling the data.
I tested my function using Advanced Rest Client, and everything worked well, meaning that the images were created successfully.
After integrating the webservice with my iPhone app i got a problem though. The function createimagefromstring returns: invalid chunk type. Even tried to generate new base64 encoded image data using a website for that purpose, and still gave me the same error. It seems that im only able to use the base64 encoded image data that use in Advanced Rest Client.
Additional info: The image i used with success is a very small image, and thus the base64 string is not big. Tried using another image (slightly biggeR) and that worked too. But bigger images doesnt seem to work.. could there be problems here ?
Desperate for help, as the integration between the iPhone app and the webservice must be done soon :)
Thanks in advance
Digging some more revealed that the imagecreatefromstring was not the source of failure.
Strange Base64 encode/decode problem
seems like the encoding removes the + characters and replaces them with space instead.
Solution to my problem so far is:
str_replace(' ','+',$image);
and then afterwards do the base64_decode.
Should anybody have a better solution, please let me know..

Uncompress gzcompress string in JavaScript (jQuery)

I have a html5 based mobile application, where I send data from the server (PHP) in textual format.
The problem is that my Data is pretty big, around 18Mo but when compressed using gzcompress it became a lot smaller.
My Problem is how uncompress the string back in JavaScript I used the plugin JXG and its working very well in both browser and simulator but the app crashes when running in my iPad 2, does any one know a better way ?
A few month ago, I made a function which uncompress gzip files... Try it... Hope this help you. If you have some question, mail me !

Categories