PHP features using remote HTTP file and FTP file operations only in php. if the allow_url_fopen option is activated in the ini file, HTTP and FTP URLs can be used in most functions that require file names as parameters to replace file names. You can also use the URL in the include, include_once, require, and require_once statements. For more information about the Protocols supported by PHP, see Supported protocols and encapsulation protocols.
Note:
To use the URL Encapsulation Protocol in PHP 4.0.3 and earlier versions, you must use the -- enable-url-fopen-wrapper parameter to configure PHP during compilation.
PHP 4.3 in Windows does not support remote access to the following functions: include, include_once, require, require_once, and imagecreatefromXXX in the GD and Image functions.
For example, you can use the following example to open files on a remote web server, parse the required output data, and then use the data for database retrieval, or simply output the content in the same style as other pages on your website.
Example #1 obtain the remote file title
Unable to open remote file.\n"; exit; } while (!feof ($file)) { $line = fgets ($file, 1024); /* This only works if the title and its tags are on one line */ if (eregi ("(.*)", $line, $out)) { $title = $out[1]; break; } } fclose($file);?>
If you have valid access permissions, you can establish a connection with an FTP server as a user and write data to the file on the FTP server. You can only use this method to create a new file. if you try to overwrite an existing file, call the fopen () function will fail.
To connect to the server with a user name other than "anonymous", you need to specify the user name (which may have a password), such as "ftp: // user: password@ftp.example.com/path/to/file "(you can also use the same syntax when accessing remote files through an HTTP protocol that requires Basic authentication ).
Example #2 save the data to a remote server
Unable to open remote file for writing.\n"; exit; } /* Write the data here. */ fwrite ($file, $_SERVER['HTTP_USER_AGENT'] . "\n"); fclose ($file);?>
Note:
It may be inspired by the above example to use this technology to store remote log files. However, as mentioned above, in the URL opened in fopen () mode, only the new file can be written. If the remote file already exists, the operation of the fopen () function will fail. To do something similar to distributed logs, refer to the syslog () function.