PHP code example of coldume / imc-stream
1. Go to this page and download the library: Download coldume/imc-stream library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
coldume / imc-stream example snippets
use ImcStream\ImcStream;
use ImcStream\Exception\TranslatedException;
ImcStream::register();
$arr = ['uri' => __FILE__];
$path = 'imc://'.serialize($arr);
try {
$fp = fopen($path, 'rb');
fread($fp, 10);
fclose($fp);
} catch (TranslatedException $e) {
echo $e->getMessage();
}
ImcStream::register(['locale' => 'zh_TW']);
use ImcStream\ImcStream;
use ImcStream\Exception\TranslatedException;
ImcStream::register();
$arr = [
'uri' => 'http://www.example.com',
'seek' => true,
];
$path = 'imc://'.serialize($arr);
try{
$fp = fopen($path, 'rb');
fseek($fp, 300);
fread($fp, 800);
rewind($fp);
fseek($fp, 500);
fread($fp, 1024);
} catch (TranslatedException $e) {
echo $e->getMessage();
}
use ImcStream\ImcStream;
use ImcStream\Exception\TranslatedException;
ImcStream::register();
$arr = [
'uri' => 'http://www.example.com',
'data_limit' => 500, // Unit in KB.
'timeout' => 5, // Unit in second.
];
$path = 'imc://'.serialize($arr);
try {
$fp = fopen($path, 'rb');
while (!feof($fp)) {
fread($fp, 1024);
}
fclose($fp);
} catch (TranslatedException $e) {
echo $e->getMessage();
}
$fp = fopen('http://www.example.com', 'rb');
fread($fp, 1024);
fclose($fp);
file_get_contents('http://www.example.com');
file_get_contents('http://www.example.com');
use ImcStream\ImcStream;
use ImcStream\Exception\TranslatedException;
ImcStream::register();
$arr = [
'uri' => 'http://www.example.com',
'seek' => true,
'global' => true,
];
$path = 'imc://'.serialize($arr);
try {
fopen($path, 'rb');
fread($fp, 1024);
fclose($path);
file_get_contents($path);
file_get_contents($path);
ImcStream::fclose($path);
} catch (TranslatedException $e) {
echo $e->getMessage();
}