Exemplos

Índice

Exemplo #1 Usando file_get_contents() para obter dados de fontes múltiplas

<?php

$arquivolocal = file_get_contents("/home/bar/foo.txt");


$arquivolocal = file_get_contents("file:///home/bar/foo.txt");


$arquivohttp = file_get_contents("http://www.example.com/foo.txt");


$arquivohttps = file_get_contents("https://www.example.com/foo.txt");


$arquivoftp = file_get_contents("ftp://usuario:senha@ftp.example.com/foo.txt");


$arquivoftps = file_get_contents("ftps://usuario:senha@ftp.example.com/foo.txt");
?>

Exemplo #2 Realizando uma requisição POST para um servidor https

<?php


$sock = fsockopen("ssl://secure.example.com", 443, $errno, $errstr, 30);
if (!
$sock) die("$errstr ($errno)\n");

$data = "foo=" . urlencode("Valor para Foo") . "&bar=" . urlencode("Valor para Bar");

fwrite($sock, "POST /form_action.php HTTP/1.0\r\n");
fwrite($sock, "Host: secure.example.com\r\n");
fwrite($sock, "Content-type: application/x-www-form-urlencoded\r\n");
fwrite($sock, "Content-length: " . strlen($data) . "\r\n");
fwrite($sock, "Accept: *
$fp = fopen("compress.zlib://foo-bar.txt.gz", "wb");
if (!
$fp) die("Não foi possível criar o arquivo.");

fwrite($fp, "Isto é um teste.\n");

fclose($fp);
?>
To Top