<?php
bool stream_context_set_params ( res $context ,
arr $params )
where,
$context = The stream or context to
apply the parameters too
$params = An array of parameters to set, should be
an associative array of the structure:
$params['paramname'] = "paramvalue"
?>
PROTOCOLS | MEANING |
file:// | LOCAL File System |
http:// | URL HTTP |
ftp:// | URL FTP |
php:// | I/O streams |
zlib:// | Data Compression stream |
data:// | DATA (RFC-2397) |
glob:// | Find Filenames |
phar:// | PHP Archive |
ssh2:// | Secure Shell 2 |
rar:// | RAR |
ogg:// | Audio |
expect:// | Interaction of stream processes |
ed48 |
SUPPORTED PARAMETERS | |
Parameters | Purpose |
notification | Name of user-defined callback function to be called whenever a stream triggers a notification. Only supported for http:// and ftp:// stream wrappers. |
options | Array of options as in context options and parameters. |
ed48 |
Attribute | Supported |
Restricted by: allow_url_fopen |
Yes |
Allows Reading | Yes |
Allows Writing | No |
Allows Appending | No |
Allows Simultaneous Reading and Writing | N/A |
Supports stat |
No |
Supports unlink |
No |
Supports rename | No |
Supports mkdir |
No |
Supports rmdir |
No |
ed48 |
<?php
Context options for http:// and https:// transports.
str method
GET, POST, or any other HTTP method
supported by the remote server.
Defaults to GET.
arr or str header
Additional headers to be sent during request.
Values in this option will override other values,
(such as User-agent:, Host:, and Authentication:).
str user_agent
Value to send with User-Agent: header.
This value will only be used
if user-agent is not specified
in the header context option above.
By default the user_agent php.ini setting is used.
str content
Additional data to be sent after the headers.
Typically used with POST or PUT requests.
str proxy
URI specifying address of proxy server.
bool request_fulluri
When set to TRUE, the entire URI
will be used when constructing the request.
(HTTP/1.0).
While this is a non-standard request format,
some proxy servers require it.
Defaults to FALSE.
int follow_location
Follow Location header redirects. Set to 0 to disable.
Defaults to 1.
int max_redirects
The max number of redirects to follow.
Value 1 or less means
that no redirects are followed.
Defaults to 20.
float protocol_version
HTTP protocol version.
Defaults to 1.0.
?>
Attribute | Supported |
Restricted by: allow_url_fopen |
Yes |
Allows Reading | Yes |
Allows Writing | Yes (new files/existing files with overwrite |
Allows Appending | Yes |
Allows Simultaneous Reading and Writing |
No |
Supports stat |
filesize,
filetype, file_exists,
is_file and is_dir elements only. As of PHP 5.1.0: filemtime. |
Supports unlink |
Yes |
Supports rename |
Yes |
Supports mkdir |
Yes |
Supports rmdir |
Yes |
ed48 |
<?php
Context options for ftp:// and ftps:// transports.
bool overwrite
Allow overwriting of already existing files
on remote server.
Applies to write mode, (uploading), only.
Defaults to FALSE.
int resume_pos
File offset at which to begin transfer.
Applies to read mode, (downloading), only.
Defaults to 0 (Beginning of File).
str proxy
Proxy FTP request via http proxy server.
Applies to file read operations only.
?>
<?php
define('PA1W', 'file://' . __DIR__ . '/adds/love.txt');
echo PA1W . "<br><br>";
$path01 = PA1W;
$fl01 = fopen($path01,"r");
// MUST EXIST
$opts01 = [ 'https' => [ 'method'=>"POST",
'header' => "Accept-language: en"] ];
$cntxt01 = stream_context_set_params($fl01, $opts01);
if($cntxt01 == TRUE)
{
echo '<br>STREAM CONTEXT IS SET AS EXPECTED<br><br>';
}
else
{
echo '<br>STREAM CONTEXT IS NOT SET AS EXPECTED<br><br>';
}
?>
<?php
define('PA2W', 'file://' . __DIR__ . '/adds');
$path02 = PA2W;
echo $path02 . "<br><br>";
$fl02 = fopen($path02 . '/sw7.jpg' ,"r");
// MUST EXIST
$opts02 = [ 'https' => [ 'method'=>"POST",
'header' => "Accept-language: en"] ];
$cntxt02 = stream_context_set_params($fl02, $opts02);
if($cntxt02 == TRUE)
{
echo '<br>STREAM CONTEXT IS SET AS EXPECTED<br><br>';
}
else
{
echo '<br>STREAM CONTEXT IS NOT SET AS EXPECTED<br><br>';
}
?>
<?php
define('PA3W', 'file://' . __DIR__ . '/adds');
echo PA3W . "<br><br>";
$path03 = PA3W;
$fl03 = @fopen($path03 . '/sw7.png' ,"r");
// DOES NOT EXIST
$opts03 = [ 'https' => [ 'method'=>"POST",
'header' => "Accept-language: en"] ];
$cntxt03 = stream_context_set_params($fl03, $opts03);
if($cntxt03 == TRUE)
{
echo '<br>STREAM CONTEXT IS SET AS EXPECTED<br><br>';
}
else
{
echo '<br>STREAM CONTEXT IS NOT SET AS EXPECTED<br><br>';
}
?>