Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top