PHP implementation code for calling components through COM classes _php tutorial

Source: Internet
Author: User
In PHP 4.2.0 to 4.2.3, external DLLs can be called using the W32api_register_function function, provided that the extended Php_w32api.dll needs to be opened in php.ini.
If you are using PHP 5, the calling DLL only uses the COM class of PHP.
The basic method is: $obj = new COM ("Server.object")
It is clear that the COM class has improved PHP functionality by a large section. This class also changes the PO invocation method of the component to the Oo method.
Before using a COM class, make sure that the following 3 conditions:
1. Enabling components: Regsvr32 component DLLs
2. Allow calls to COM:php.ini in com.allow_dcom =true
3. Account has access to the component
You can then call it directly using the COM function of PHP.
$obj = new COM ("ABC. MYOBJ "); General front is the main file name, followed by the class name, the registration table 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 CodeThe code is as follows:
$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;
?>
$obj = new COM ("Server.object")
That is, you can use the properties and methods of COM objects.
The following is an example of word
Start Word
$word = new COM ("Word.Application") or Die ("Unable to instanciate word");
Print "ioaded Word, Version {$word->version}\n";
Before placing it
$word->visible = 1;
Open an empty document
$word->documents->add ();
Do something, whatever.
$word->selection->typetext ("This is a test ...");
$word->documents[1]->saveas ("Useless test.doc");
Close Word
$word->quit ();
Releasing objects
$word->release ();
$word = null;
?>
$com =new com (' Scripting.FileSystemObject '); FSO to use the absolute path of the
$file = $com->getfile (__file__); Absolute path
$file->attributes= ' 6 '; Modify properties to System, hide
Constant Value Description
Normal 0 ordinary files. Do not set properties.
ReadOnly 1 read-only files. The property is read/write.
Hidden 2 hidden files. The property is read/write.
System 4 Systems files. The property is read/write.
Volume 8 disk drive volume label. property is read-only.
Directory 16 folders or directories. property is read-only.
Archive 32 files have been modified since the last backup. The property is read/write.
Alias 64 links or shortcuts. property is read-only.
Compressed 128 compressed files. property is read-only.
?>

The way to hide files in PHP is the code above.
Copy CodeThe code is as follows:
This can realize ASP's XMLHTTP function of horse-passing
$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: The URL of the Service Web page.
Varasync: Whether to execute synchronously. The default is true, which 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 either XML format data or a string, stream, or an array of unsigned integers. It is also possible to omit the instruction from the URL parameter of the Open method.
setRequestHeader (Bstrheader, Bstrvalue)
Bstrheader:http Head (header)
Bstrvalue:http Header Value If the open method is defined as post, you can define how the form is uploaded:
Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded")
XMLHTTP Property
onReadyStateChange: Gets the event handle of the returned result in synchronous execution mode. Can only be called in the DOM.
Responsebody: The result is returned as an array of unsigned integers.
Responsestream: The result is returned as a IStream stream.
ResponseText: The result is returned as a string.
Responsexml: The result is returned as XML format data.
*/
?>

http://www.bkjia.com/PHPjc/324949.html www.bkjia.com true http://www.bkjia.com/PHPjc/324949.html techarticle in PHP 4.2.0 to 4.2.3, external DLLs can be called using the W32api_register_function function, provided that the extended Php_w32api.dll needs to be opened in php.ini. If you are using PHP 5, call ...

  • 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.