-1

I would like some advice about what would be the best practice from a design perspective when tackling this problem:

  • I have a website that is currently displaying an "image" generated by google maps.
  • This website runs on an Apache web server in Linux.
  • I would like to generate my own "image" using my own program (my program.c), not the google maps library.
  • My program (my_program.c) is written in in C. I have the option of installing it into the same machine as the Apache web server, or a separate machine.

I need to: 1) somehow call this C program, or preferably a function inside this program (my_program.c) from the PHP code, 2) Access the MySQL database via the C program, and perform some calculations that would ultimately render the image desired 3) Return the results of this process (the image that was generated) to the PHP program so that it can be displayed in the browser.

Any tips would be appreciated.. Thanks.

4

1 回答 1

1

1) 从 PHP 代码调用这个 C 程序:

将编译后的程序放在 /cgi-bin 文件夹中,并通过查询字符串从 PHP 传递参数。printf("Content-Type: image/png\r\n\r\n");确保您的代码在任何图像数据(例如, )之前至少发送一个 Content-Type HTTP 标头

2)通过C程序访问MySQL数据库:

使用MySQL C API

3) 将此过程生成的图像返回给 PHP 程序,以便在浏览器中显示。

您可能不需要向 PHP 返回任何内容。只需在 HTML 代码中嵌入 CGI 应用程序的链接,例如,

<img src="http://example.com/cgi-bin/my-map-tool?lat=+42.5;long=-0.5" />
于 2015-06-09T00:21:55.780 回答