o şekildede istediğim şey olmuyor ne yazıkki...
aslında bunun bir yöntemi var ama matematiksel işlemler döndüğü için yanlış bir +1 -1 hataya sebep olucaktır...
normalde dosya gönderilirken örn: 5kb sınırlamalı bir dosya (ilk part)
1-5
6-10
11-15
vs... şeklinde gönderildiğini varsayalım... 100kb toplam boyutlu dosya için idm benden ikinci part olarak 20-30 kb yi üçüncü part olarak 60-70 kb'yi isteyecektir... benim bu ikinci ve üçüncü istekleri iptal etmem gerek....
fakat aşağıdaki kodu tamamen devre dışı bırakırsam.... ilk part 10kb da durdurulup tekrar başladığında aşağıdaki kod olmadığı için devam edemeyecek ve sıfırlanıcaktır... gerekirse bu son gönderilen byte'ı kullanıcının hesabında bir veri olarak yazıp bu değerdeki istek yani durdurduktan sonra çalıştırdığında 11-15 arası kb lar istediğinde aşağıdaki kod öbeği tekrar aktif olarak devam edebilme özelliğini bu şekilde başarmış olabilirim....
if(isset($_SERVER['HTTP_RANGE']) && preg_match('/^bytes=(\d+)-(\d*)/', $_SERVER['HTTP_RANGE'], $arr))
{
// Starting byte
$start=$arr[1];
if($arr[2]){
// Ending byte
$end=$arr[2];
}
}Fakat buradaki matematiksel işlemde +1 -1 değerleri ile okunan veya istenen veriler kafamı esas bulandıranlar aşağıdaki örnek bir kodu gönderiyorum bir kaç sistem buldum bununla ilgili ama çalışmıyor istediğim yöntemle...
<?php
// If user click the download link
if(isset($_GET['dosya']))
{
$local_file = $_GET[dosya];
$parts = Explode('/', $local_file);
$file_name = $parts[count($parts) - 1];
// The directory of downloadable files
// This directory should be unaccessible from web
// Replace the slash and backslash character with empty string
// The slash and backslash character can be dangerous
// If the requested file is exist
if(file_exists($local_file))
{
// Get the file size
$file_size=filesize($local_file);
// Open the file
$fh=fopen($local_file, "r");
// Download speed in KB/s
$speed=5;
// Initialize the range of bytes to be transferred
$start=0;
$end=$file_size-1;
// Check HTTP_RANGE variable
if(isset($_SERVER['HTTP_RANGE']) && preg_match('/^bytes=(\d+)-(\d*)/', $_SERVER['HTTP_RANGE'], $arr))
{
// Starting byte
$start=$arr[1];
if($arr[2]){
// Ending byte
$end=$arr[2];
}
}
// Check if starting and ending byte is valid
if($start>$end || $start>=$file_size){
header("HTTP/1.1 416 Requested Range Not Satisfiable");
header("Content-Length: 0");
}
else
{
// For the first time download
if($start==0 && $end==$file_size)
{
// Send HTTP OK header
header("HTTP/1.1 200 OK");
}
else
{
// For resume download
// Send Partial Content header
header("HTTP/1.1 206 Partial Content", false);
// Send Content-Range header
header("Content-Range: bytes ".$start."-".$end."/".$file_size);
}
// Bytes left
$left=$end-$start+1;
// Send the other headers
header("Content-Type: application/octet-stream");
header("Accept-Ranges: bytes");
// Content length should be the bytes left
header("Content-Length: ".$left);
header("Content-Disposition: attachment; filename=".$file_name);
// Read file from the given starting bytes
fseek($fh, $start);
// Loop while there are bytes left
while($left>0)
{
// Bytes to be transferred
// according to the defined speed
$bytes=$speed*1024;
// Read file per size
echo fread($fh, $bytes);
// Flush the content to client
flush();
// Substract bytes left with the tranferred bytes
$left-=$bytes;
// Delay for 1 second
sleep(1);
}
}
fclose($fh);
}
else
{
// If the requested file is not exist
// Display error message
echo "File not found!";
}
exit();
}
?>