I'm building an API in PHP which accesses a mysql database, which stores a series of articles, containing the html-formatted text and images. I am able to echo the html to the device using an http request, and although the images display (linked by img src) but this doesn't download the html and images in one package. I will want to archive the articles individually so it would be nice to download it separately. I'm considering zipping it up with PHP and downloading it with the client app, but I'm not sure. Any advice is appreciated.
How can I package html data (html text, images, etc) in PHP so a client can access it (iOS, Android)
Asked
Active
Viewed 149 times
1 Answers
0
You could try the data URI scheme. It allows you to encode an image file directly into your HTML code.
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" />
That example is taken from this Wikipedia article, which also provides a PHP example. It's very easy to do.
The caveat to this is browser support but it sounds like most modern browsers, including mobile, should support it. Give it a go and see, should take no time to implement and you'll know right away if it's the right solution.

verv
- 686
- 4
- 7
-
Thanks, that's a great thing to know about. Will this make my files too large? There are about 4 images per html file, which are each roughly 400x400px – TDash Aug 16 '13 at 01:48
-
I'm not really sure. I mean at they very least your HTML file will increase by the size of the images. I'm not sure if base64 encoding also INCREASES the byte size, to be honest. It's pretty easy to do with existing PHP functions though. Grab the example from the wikipedia page and try it - you'll know then :) – verv Aug 16 '13 at 05:59