手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表2008年09月16日的文章

闲着无聊,用WPS生成文档

不好意思,该操作只能在windows服务器上才能执行,是因为,只有windows服务器才支持COM功能,而且,必须安装wps(这点应该不难,因为WPS是免费软件)
免费软件这点太重要了,如果你要生成WORD,你不可能安装一个OFFICE吧,office太贵了。

PHP代码
  1. <?php  
  2. $wps = new COM("WPS.Application");  
  3. $wps->Visible = false;  
  4. $doc = $wps->Documents->Add();  
  5. $doc->Range->Text = 'WPS FOR PHP test';  
  6. $doc->Paragraphs[1]->Alignment = 1;  
  7. $doc->Shapes->AddPicture("http://img.kingsoft.com/publish/kingsoft/images/gb/sy/logo.gif", 100, 50, 148, 60);  
  8. $doc->SaveAs('c:\\temp\\test1.wps');  
  9. $doc->Close();  
  10. $wps->Quit();  
  11. unset( $doc , $wps );  
  12. ?>  

代码很简单,只是添加了一个文字和一个图片而己。但是,证明了是可以使用这个功能。
大家别忘了,WPS的附加功能可是很多的,比如把文件转为PDF等格式。也就是说, 如果是在windows服务器上,我们要生成PDF,可以不使用那些什么fpdf类库,而是使用WPS先生成一个WORD格式的文档,然后直接exportPdf就可以了。要知道OFFICE默认并不支持这种功能。黑黑

这也是一种思路嘛,思路决定出路,转换一种思路,可能就是海阔天空。

这里是WPS的开发者网站:http://wps.kingsoft.com/apply/engineer.shtml,从这里可以下载API:http://wps.kingsoft.com/download/WPSAPI.zip

Tags: php, wps, com, wps application

为windows的WEB服务器添加高性能的FTP组件

在windows服务器里面,如果我们要用FTP函数,速度应该是很慢的,而且效率不高,如果有大量文件需要上传,用自带的FTP函数,恐怕是要死人的吧。
windows服务器,windows哦,可以装N多软件的windows哦。虽然不建议在服务器上装上很多软件,但是也可以装一些FTP软件的嘛。这里以cuteftp举例。
cuteftp安装完毕后,会在软件目录里有一个Scripts目录,现在的版本不象很久以前的了,如今的版里只有一个Sample.vbs,记得几年前的cuteftp里面会有各种各样的vbs文件的。
闲话不多说,打开vbs文件,内容为:

ASP/Visual Basic代码
  1. 'This default template script is in VBScript. You can write scripts in your language of choice and save them with the proper extension, or use your an editor specific to that language.  
  2. 'See the TESDK help file for more details on how the scripting feature works and for information on each supported method and property.  
  3. 'You must have Windows Scripting Host installed for the COM enabled engine to work. Run the Transfer Engine once to register it (as a COM object) on the target system.  
  4. 'If you're having problems with running scripts while not logged in, or when trying to run them using MS scheduler, refer to our online knowledgebase for help (http://www.globalscape.com/support)  
  5. 'Look into c:\temp folder to observe local activity (for testing purposes) or right click on the Transfer Engine icon in the systray and select "show current transfers"  
  6. 'This sample script performs an anonymous login to ftp://ftp.globalscape.net  
  7.    'First declare a variable called Mysite. This will hold the reference to the TE COM object.  
  8.    Dim MySite  
  9.    'Create a connection object and assign it to the variable  
  10.    Set MySite = CreateObject("CuteFTPPro.TEConnection")  
  11.    ' Now set each property for the site connection   
  12.    ' You can omit this section to use the default values, but you should at least specify the Host  
  13.    'The default Protocol is FTP, however SFTP (SSH2), FTPS (SSL), HTTP, and HTTPS can also be used)  
  14.    MySite.Protocol = "FTP"  
  15.    MySite.Host = "ftp.globalscape.com"  
  16.    'following lines are optional since the default is anonymous if no login and password are defined  
  17.    MySite.Login = "anonymous"  
  18.    MySite.Password = "user@user.com"  
  19.    'if necessary, use the UseProxy method and ProxyInfo or SocksInfo properties to connect through a proxy server  
  20.    MySite.UseProxy = "BOTH"  
  21.    'now connect to the site (also called called implicitly when most remote methods are called)  
  22.    MySite.Connect  
  23.    'perform some logic to verify that the connection was made successfully  
  24.    If (Not Cbool(MySite.IsConnected)) Then    
  25.       MsgBox "Could not connect to: " & MySite.Host & "!"  
  26.       Quit(1)  
  27.    End If  
  28.    'The script will now check to see if the local folder c:\temp exists and will create it if necessary  
  29.    If (Not (MySite.LocalExists("c:\temp"))) Then  
  30.       MySite.CreateLocalFolder "c:\temp"  
  31.    End If  
  32.    'Change TE's local working folder to to c:\temp  
  33.    MySite.LocalFolder = "c:\temp"  
  34.    'Check for existence of remote folder "/pub/cuteftp"  
  35.    b = MySite.RemoteExists("/pub/cuteftp/")  
  36.    If (Not CBool(b)) Then  
  37.       'Verify existence of remote folder  
  38.       MsgBox "Remote folder not found!. Please make sure that the Pub folder exists on the remote site"  
  39.       Quit(1)  
  40.    End If  
  41.    'Now download the index file to the local destination folder  
  42.    MySite.Download "/pub/cuteftp/index.txt"  
  43.    'Complete.  Show the status of this transfer.  
  44.    MsgBox "Task done, final status is '" + MySite.Status + "'"  
  45.   MySite.Disconnect  
  46.   MySite.Close  
  47. 'End of sample script. You can save you script and then run it by either selecting it from the Tools > Run Script menu or by double clicking on the script file in Windows  

看到这样的文件,你应该知道如何调用一些FTP软件自带的方法了吧?现在,我们用PHP模拟一遍。。。。。
请看详细内容

» 阅读全文

Tags: ftp, com, windows, cuteftp, vbs

精通MYSQL数据库——连载七

今天我们继续学习一下MYSQL的数据类型
浮点型
从MYSQL3.23开始,FLOAT和DOUBLE类型就一直分别对应着IEEE标准所定义的单精度浮点数和双精度浮点数,绝大多数编程语言也都支持这两种数据类型。
当某个字段设置成这两种类型时,会要求按(m,d)这样的格式输入参数,其中m和上文介绍INT时所讲的m效果一样,仅仅在显示/打印结果时有一定的排版作用,而对数据的精确度没有影响。可是d这个参数就不一样了,d代表了小数点后面的数字个数,而且会按照d的大小来进行四舍五入,例如:1234.5678如果存储到FLOAT(8,3)这样的字段里,实际存放的是1234.568,最后一位会四舍五入。
存储FLOAT和DOUBLE时,如果超出了这两种类型的范围,将会被替换成该类型的最大可取值(一般由当前操作系统决定,我不知道MYSQL是怎么样。),可以使用SHOW WARNING来查看警告内容。
MYSQL对浮点数有一定的要求,即一定要符合通用计数法,小数点一定是“.”,而不能是“,”(因为有部分欧洲国家使用逗号作为小数点,我也是第一次听说,黑黑),MYSQL永远会以这种写法向客户返回查询结果,只有在非常大或非常小的数值,会采用科学计数法表示,如1.234E+017。如果想让浮点数表现形式变成其他样式,有两种方式:一是利用SQL查询中的FORMAT函数,二是用客户端程序中的FORMAT函数,例如php中就可以使用sprintf或者number_format等来改变显示效果

类型 含义
FLOAT(m,d) 单精度浮点数,8位精度,占4字节
DOUBLE(m,d) 双精度浮点数,16位精度,占8字节
REAL(m,d) DOUBLE的同义词



说到浮点数,当然要提定点数
正因为MYSQL在处理浮点数时,最后一位会被自动的四舍五入,而我们实际上并不需要这一位被四舍五入(比如在处理财务数据时),怎么办呢?定点数可以解决这个问题。
定点数(DECIMAL)数字是以字符串的形式来进行存储的,并且不被允许存储指数形式,每位数字占用一个字节,外加两个字节的开销,所以,占用了更多的空间,但可表示的数值范围却比较小。
在进行存储的时候,也有两个参数DECIMAL(p,s)这回,这两个参数都有作用了。p代表了数据的总位数(不含小数点),最大65,s代表了小数点后的数字位数,最大为30。比方说:DECIMAL(6,3)取值范围为-999.999~999.999,这是新的版本的表示方法。不知道我有没有记错,我记得在以前的版本里,DECIMAL(6,3),这个6并不是代表了总位数,而是小数点前的位数(可能是在4.0吧)。
在MYSQL内部,定点数是被保存为二进制格式的,把定点数从小数点开始分割,并为它们各自分配所占用的字节数(最初是以每4个字节进行划分,虽然每个字节可以容纳2位数字,但4个字节却可以容纳9位数字,超过4个字节后,如果有多出的数字就划分一个字节来进行存储,同样如果是9位数字,还是只占4个字节)。根据这个规定,我们可以认为DECIMAL(6,3)其实是和DECIMAL(18,9)占用了同样多的字节数(8个字节)。如此说来DECIMAL(19,9)实际就占用了9个字节。

类型 含义
DECIMAL(p,s) 定点数,以字符串形式保存,最长为65
NUMERIC,DEC 同上(应该没有记错吧)

参考:http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html

Tags: database, mysql, 连载