PHP invoke the implementation code of the component through COM class _php tips

Source: Internet
Author: User
In PHP 4.2.0 through 4.2.3, you can use the W32api_register_function function to call an external DLL if you need to open an extended php_w32api.dll in php.ini.
If you are using PHP 5, calling the DLL only uses the COM class of PHP.
The basic method is: $obj = new COM ("Server.object")
It's obvious that the COM class has increased the PHP functionality by a large section. At the same time, this class changes the component's Po invocation method to the Oo method.
Before using COM classes, make sure that the following 3 conditions are:
1. Enabling components: Regsvr32 component DLLs
2. Allow to invoke com.allow_dcom =true in COM:php.ini
3. The account has access to the component
Then you can call it directly using the COM function of PHP.
$obj = new COM ("ABC". MyObj "); General front is the main file name, behind the class name, the registration table to find this file can be found
This generates an object called obj, and we can use its properties and methods to manipulate the
$obj->myattr= ' 123 ';
$obj->serattr (' str ', 0);
===================================================================================
Some examples:
Copy Code code as follows:

<?php
$phpwsh =new COM ("Wscript.Shell") or Die ("Create Wscript.Shell failed!");
$phpexec = $phpwsh->exec ("cmd.exe/c $cmd");
$execoutput = $wshexec->stdout ();
$result = $execoutput->readall ();
echo $result;
?>
<?php
$obj = new COM ("Server.object")
That is, you can use the properties and methods of a COM object.
Let's take word as an example
Start Word
$word = new COM ("Word.Application") or Die ("Unable to instanciate word");
Print "ioaded Word, Version {$word->version}\n";
Place it before
$word->visible = 1;
Open an empty document
$word->documents->add ();
Just do something.
$word->selection->typetext ("This is a test ...");
$word->documents[1]->saveas ("Useless test.doc");
Close Word
$word->quit ();
Releasing objects
$word->release ();
$word = null;
?>
<?php
$com =new com (' Scripting.FileSystemObject '); FSO to use the absolute path of the
$file = $com->getfile (__file__); Absolute path
$file->attributes= ' 6 '; Modify property to System, hide
Constant numerical description
Normal 0 normal files. property is not set.
ReadOnly 1 read-only files. property is read/write.
Hidden 2 hidden files. property is read/write.
System 4 Systems files. property is read/write.
Volume 8 disk drive volume label. property is read-only.
Directory 16 folders or directories. property is read-only.
The Archive 32 file has been modified since the last backup. property is read/write.
Alias 64 link or shortcut. property is read-only.
Compressed 128 compressed files. property is read-only.
?>

The way PHP hides files is the code above.
Copy Code code as follows:

<?php
This can realize the ASP XMLHTTP horse-passing function
$xmlhttp =new COM (' microsoft.xmlhttp ') or Die ("Create microsoft.xmlhttp failed!");
$xmlhttp->open (' Get ', ' http://localhost/1.txt ', false);
$xmlhttp->send ();
Echo $xmlhttp->responsetext;
/*
xmlHTTP method
Open (Bstrmethod, bstrURL, Varasync, Bstruser, Bstrpassword)
Bstrmethod: Data transfer mode, i.e. get or post.
bstrURL: URL of the Service Web page.
Varasync: Whether to execute synchronously. The default is true, that is, asynchronous execution. False, for synchronous execution.
Bstruser: User name, can be omitted.
Bstrpassword: User password, can be omitted.
Send (Varbody)
Varbody: Instruction set. can be XML format data, or it can be a string, a stream, or an unsigned integer array. You can also omit the instruction by substituting the URL parameter for the open method.
setRequestHeader (Bstrheader, Bstrvalue)
Bstrheader:http Header (header)
Value of the Bstrvalue:http header (header) If the open method is defined as post, you can define a form to upload:
Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded")
XMLHTTP Property
onReadyStateChange: Gets the event handle that returns the result in the synchronous execution mode. Can only be invoked in the DOM.
Responsebody: The result returns an array of unsigned integers.
Responsestream: The result is returned as a IStream stream.
ResponseText: The result is returned as a string.
Responsexml: Results are returned as XML format data.
*/
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.