How can I package html data (html text, images, etc) in PHP so a client can access it (iOS, Android)

StackOverflow https://stackoverflow.com/questions/18263758

Вопрос

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.

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top