标签:com

浏览模式: 标准 | 列表 | 图文

闲着无聊,用WPS生成文档

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

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

代码很简单,只是添加了一个文字和一个图片而己。但是,证明了是可以使用这个功能。
大家别忘了,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

7d8e79d4311db07d51119a4eb56344fe

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

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

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

'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.
'See the TESDK help file for more details on how the scripting feature works and for information on each supported method and property.
'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.
'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)
'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"
'This sample script performs an anonymous login to ftp://ftp.globalscape.net
'First declare a variable called Mysite. This will hold the reference to the TE COM object.
Dim MySite
'Create a connection object and assign it to the variable
Set MySite = CreateObject("CuteFTPPro.TEConnection")
' Now set each property for the site connection
' You can omit this section to use the default values, but you should at least specify the Host
'The default Protocol is FTP, however SFTP (SSH2), FTPS (SSL), HTTP, and HTTPS can also be used)
MySite.Protocol = "FTP"
MySite.Host = "ftp.globalscape.com"
'following lines are optional since the default is anonymous if no login and password are defined
MySite.Login = "anonymous"
MySite.Password = "user@user.com"
'if necessary, use the UseProxy method and ProxyInfo or SocksInfo properties to connect through a proxy server
MySite.UseProxy = "BOTH"
'now connect to the site (also called called implicitly when most remote methods are called)
MySite.Connect
'perform some logic to verify that the connection was made successfully
If (Not Cbool(MySite.IsConnected)) Then
MsgBox "Could not connect to: " & MySite.Host & "!"
Quit(1)
End If
'The script will now check to see if the local folder c:\temp exists and will create it if necessary
If (Not (MySite.LocalExists("c:\temp"))) Then
MySite.CreateLocalFolder "c:\temp"
End If
'Change TE's local working folder to to c:\temp
MySite.LocalFolder = "c:\temp"
'Check for existence of remote folder "/pub/cuteftp"
b = MySite.RemoteExists("/pub/cuteftp/")
If (Not CBool(b)) Then
'Verify existence of remote folder
MsgBox "Remote folder not found!. Please make sure that the Pub folder exists on the remote site"
Quit(1)
End If
'Now download the index file to the local destination folder
MySite.Download "/pub/cuteftp/index.txt"
'Complete. Show the status of this transfer.
MsgBox "Task done, final status is '" + MySite.Status + "'"
MySite.Disconnect
MySite.Close
'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软件自带的方法了吧?

由于windows版本下的PHP直接就支持COM,所以现在我们可以直接用PHP模拟一遍:

<?php

$ftp = new COM("CuteFTPPro.TEConnection");

$ftp->Protocol = "FTP";
$ftp->Host = "ftp.globalscape.com";

$ftp->Login = "anonymous";
$ftp->Password = "user@user.com";

$ftp->UseProxy = "BOTH";
$ftp->Connect();

if ( !$ftp->IsConnected ){
die("Could not connect to : {$ftp->Host}");
}

if ( !$ftp->LocalExists('c:\\temp') ){
$ftp->CreateLocalFolder('c:\\temp');
}

$ftp->LocalFolder = 'c:\\temp';

$remote = $ftp->RemoteExists('/pub/cuteftp/');
if ( !$remote ){
die('Remote folder not found!. Please make sure that the Pub folder exists on the remote site');
}

$ftp->Download('/pub/cuteftp/index.txt');
echo( 'Over,ftp Status:' . $ftp->Status );
$ftp->Disconnect();
$ftp->Close();


?>

执行一下,OK,显示:Over,ftp Status:FINISHED,同时c盘根目录下有一个temp目录,里面下载了那个:index.txt文件。测试完毕。。(PS:对于这样的转换实在没有技术含量啊。呵呵,直接把“.”换成“->”就完事了。)
更多的函数,请参考cuteftp帮助文件:

7d8e79d4311db07d51119a4eb56344fe