search
HomeBackend DevelopmentPHP Tutorial用Flash图形化数据(一)_php基础

by Bryan Mattern  一木 译

SWF和Flash简介
    SWF是Macromedia Flash用来在Internet上向用户传送图片、动画和声音的文件格式。Flash是你能够向用户提供一个丰富的和动态的界面。大约90%的Web用户不用安装浏览器插件就可以浏览SWF内容,超过2亿人下载了Flash播放器。Macromedia在1998年4月公开了SWF规范。在PHP4中加入SWF的支持。
    PHP内建的动态生成图片的能力是一个吸引我的特征。它可以生成看起来更专业更让人舒服的报表和界面。一开始,我用充斥在网上的各种GD代码来创建图片来显示我的不同项目的数据。但我很快就被生成的图片的不确定搞烦了,决定试试看能不能用矢量图形来解决问题。我想你也会同意,结果看起来好多了。如果一个图片能代表一千个词,想象一下一幅Flash动画代表什么?
    我将尽量使这个例子简单一些,只说说基础的东西。我的目的只是创建一个容纳GD生成的GIF和PNG图片的Drog in。你可以加入对它的扩展和增强,比如Flash赖以出名的各种可视效果。例如,你可以制作在载入页面时的图形淡入、飞舞,或者动态的显示几片雪花。你的想象力是对PHP的SWF函数的唯一限制。
    怎样取得需要图形化的数据最好留给读者去练习。因为这篇文章是关于动态创建Flash文件的,我将在例子中使用一个假想的表作为数据集来创建它的图形化视图。你需要检查你的数据,决定采用一种最适合的图表形式。在多数情况下,饼图是一个合适的选择,这也是我的例子要采用的图表形式。折线图、柱状图或者面积图都可以用相似的方式创建。
    在这个例子中,假定我们把一些包裹送到了几个城市,而我们要看看每个城市收到的包裹所占的比例。我们决定把数据存储在数据库“world”的表“city”中。让我们先建立这个表,并输入这个例子需要的数据。

#
# Table structure for table 'city'
#

DROP TABLE IF EXISTS city;
CREATE TABLE city (
   city_id int(14) NOT NULL auto_increment,
   city_name varchar(255) NOT NULL,
   city_timestamp timestamp(14),
   PRIMARY KEY (city_id)
);

#
# Dumping data for table 'city'
#

INSERT INTO city VALUES( '1', 'London', '20000917122625');
INSERT INTO city VALUES( '2', 'London', '20000917122626');
INSERT INTO city VALUES( '3', 'London', '20000917122626');
INSERT INTO city VALUES( '4', 'London', '20000917122627');
INSERT INTO city VALUES( '5', 'Paris', '20000917122631');
INSERT INTO city VALUES( '6', 'Paris', '20000917122632');
INSERT INTO city VALUES( '7', 'New York', '20000917122644');
INSERT INTO city VALUES( '8', 'New York', '20000917122645');
INSERT INTO city VALUES( '9', 'New York', '20000917122646');
INSERT INTO city VALUES( '10', 'New York', '20000917122646');
INSERT INTO city VALUES( '11', 'New York', '20000917122647');
INSERT INTO city VALUES( '12', 'Hong Kong', '20000917122654');


配置你的系统以使用SWF
    我用的环境是RedHat Linux6.2, Apache 1.3.12, PHP 4.0.2(编译为Apache模块)。如果你在Windows中使用PHP,事情会有些不同。你需要下载或者编译一个Flash Dll,但是不需要修改代码。
    PHP通过Paul Haeberli的libswf模块来提供创建Shockwave Flash 文件的能力。你需要从http://reality.sgi.com/grafica/flash/下载libswf。然后,你需要使用选项--with-swf[=DIR]来配置PHP,这里DIR是include和lib目录所在的目录。include目录下必须有swf.h文件,而lib目录下必须有libswf.a文件。当解压缩下载的libswf发布版本的时候,这两个文件会被解压缩到同一个目录。你需要把这两个文件移到正确的位置。完成后,目录结构应该像下面的样子:

    /usr/local/swf/
        /include/
            swf.h
        /lib/
            libswf.a
        /fonts
    ...

    为了使SWF函数能正常工作,你需要复制/usr/local/swf/fonts/目录,以便web服务器能访问该目录(对apache和mod_php来说,最好的办法就是使用绝对路径,并把以上目录复制到apache的文档根目录下。)另外,在libswf的发布版本中有一个很小的c程序,能够把类型1的字体转换成Flash能用的字体。
    因为我们要动态地创建和写SWF文件,所以web服务器需要在存储文件的目录有写权限。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP's Purpose: Building Dynamic WebsitesPHP's Purpose: Building Dynamic WebsitesApr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP: Handling Databases and Server-Side LogicPHP: Handling Databases and Server-Side LogicApr 15, 2025 am 12:15 AM

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

How do you prevent SQL Injection in PHP? (Prepared statements, PDO)How do you prevent SQL Injection in PHP? (Prepared statements, PDO)Apr 15, 2025 am 12:15 AM

Using preprocessing statements and PDO in PHP can effectively prevent SQL injection attacks. 1) Use PDO to connect to the database and set the error mode. 2) Create preprocessing statements through the prepare method and pass data using placeholders and execute methods. 3) Process query results and ensure the security and performance of the code.

PHP and Python: Code Examples and ComparisonPHP and Python: Code Examples and ComparisonApr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP in Action: Real-World Examples and ApplicationsPHP in Action: Real-World Examples and ApplicationsApr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: Creating Interactive Web Content with EasePHP: Creating Interactive Web Content with EaseApr 14, 2025 am 12:15 AM

PHP makes it easy to create interactive web content. 1) Dynamically generate content by embedding HTML and display it in real time based on user input or database data. 2) Process form submission and generate dynamic output to ensure that htmlspecialchars is used to prevent XSS. 3) Use MySQL to create a user registration system, and use password_hash and preprocessing statements to enhance security. Mastering these techniques will improve the efficiency of web development.

PHP and Python: Comparing Two Popular Programming LanguagesPHP and Python: Comparing Two Popular Programming LanguagesApr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

The Enduring Relevance of PHP: Is It Still Alive?The Enduring Relevance of PHP: Is It Still Alive?Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.