Serving Images to get a request

倖福魔咒の 提交于 2019-12-31 05:32:45

问题


I am using CodeIgniter rest Controller. I want to be able to serve images on GET requests made by the client.

Is this the best option or should i just provide a link to the image and let the client download it themselves? If I can serve the images itself, than how should I?


回答1:


To make CodeIgniter set the proper headers and such you could do this in your controller:

$this->output->set_content_type('jpeg')->set_output(file_get_contents('path_to_file'));

And it will output (as request response) the image content as a file. No view required.

Please note though that this is a bit of extra overhead as the file is processed by PHP instead of just the webserver (Apache/Nginx). It only makes sense if you need to have some business logic on the request, such as logging or authorization (though even that can be done without PHP). If you are just outputing the image it is therefor better to link straight to file and leave PHP out of it.




回答2:


I think You could show the images to client and give them a check-boxes to download the images as a Zip file.

See this



来源:https://stackoverflow.com/questions/12246246/serving-images-to-get-a-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!