$url = 'https://example.com'; $options = [ 'http' => [ 'method' => 'GET', 'header' => 'Accept-language: en\r\n', 'user_agent' => 'Mozilla/5.0', ], ]; $context = stream_context_create($options); $response = file_get_contents($url, false, $context);
$ftp_url = 'ftp://example.com/file.txt'; $options = [ 'ftp' => [ 'overwrite' => true, 'username' => 'user', 'password' => 'pass', ], ]; $context = stream_context_create($options); file_put_contents($ftp_url, 'hello world', 0, $context);In this example, we are setting the `overwrite`, `username`, and `password` options for an FTP write request to the specified URL. Package/Library: PHP Standard Library (Core)