- if (!ctype_digit ($start) || $start < 0
- || !ctype_digit ($length) || $length <= 0)
- {
- echo "Error";
- return;
- }
-
- $p = VAR_BLOCK . s2p ($id) . $id;
- if (!file_exists ($p))
- {
- echo "Error";
- return;
- }
-
- /* Check date. */
- $f = file ($p . '_infos');
- $date = trim ($f[0]);
- $block_size = trim ($f[1]);
- $stored_code = trim ($f[2]);
- /* Update date. */
- if (date ('U') - $date > JIRAFEAU_HOUR
- && date ('U') - $date < JIRAFEAU_MONTH)
- {
- if (file_put_contents ($p . '_infos', date ('U') . NL . $block_size . NL . $stored_code) === FALSE)
- {
- jirafeau_block_delete_ ($id);
- echo "Error";
- return;
- }
- }
- /* Remove data. */
- elseif (date ('U') - $date >= JIRAFEAU_MONTH)
- {
- echo date ('U'). " $date ";
- jirafeau_block_delete_ ($id);
- echo "Error";
- return;
- }
-
- if ($start + $length > $block_size)
- {
- echo "Error";
- return;
- }
-
- /* Read content. */
- header ('Content-Length: ' . $length);
- header ('Content-Disposition: attachment');
-
- $r = fopen ($p, 'r');
- if (fseek ($r, $start) != 0)
- {
- echo "Error";
- return;
- }
- $c = 1024;
- for ($cnt = 0; $cnt < $length && !feof ($r); $cnt += 1024)
+ $fs = filesize ($fp_src);
+ if ($fs === false || $fs == 0 || !(extension_loaded('mcrypt') == true))
+ return '';
+
+ /* Prepare module. */
+ $m = mcrypt_module_open('rijndael-256', '', 'ofb', '');
+ /* Generate key. */
+ $crypt_key = jirafeau_gen_random (10);
+ $md5_key = md5($crypt_key);
+ $iv = jirafeau_crypt_create_iv ($md5_key, mcrypt_enc_get_iv_size($m));
+ /* Init module. */
+ mcrypt_generic_init($m, $md5_key, $iv);
+ /* Crypt file. */
+ $r = fopen ($fp_src, 'r');
+ $w = fopen ($fp_dst, 'c');
+ while (!feof ($r))