Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8638671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:47:46+00:00 2026-06-12T10:47:46+00:00

I have sort of a beginning of a solution. I wrote this function (Sorry

  • 0

I have sort of a “beginning” of a solution.
I wrote this function (Sorry about the spacings):

<?php
set_time_limit(0);

// Just to get the remote filesize

function checkFilesize($url, $user = "", $pw = ""){

 ob_start();

 $ch = curl_init($url);

 curl_setopt($ch, CURLOPT_HEADER, 1);

 curl_setopt($ch, CURLOPT_NOBODY, 1);

 if(!empty($user) && !empty($pw)){

  $headers = array('Authorization: Basic ' .  base64_encode("$user:$pw"));

  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

 }

 $ok = curl_exec($ch);

 curl_close($ch);

 $head = ob_get_contents();

 ob_end_clean();

 $regex = '/Content-Length:\s([0-9].+?)\s/';

 $count = preg_match($regex, $head, $matches);

 return isset($matches[1]) ? $matches[1] : "unknown";

}

// Split filesize to threads

function fileCutter($filesize,$threads){

 $calc = round($filesize / count($threads));

 $count = 0;

 foreach($threads as $thread){

  $rounds[$count] =  $calc;

  $count++;

 }

 $count = 0;

 foreach($rounds as $round){

  $set = $count + 1;

  if($count == 0){

   $from = 0;

  } else {

   $from = ($round * $count);

  }

  $cal = ($round * $set);

  $final[$count] = array('from'=>$from,'to'=>$cal);

  $count++;

 }

 // Correct the "Rounded" result

 $end = end($final);

 $differance = $filesize - $end['to'];

 if (strpos($differance,'-') !== false) {} else {$add = '+';}

 $end_result =  ($end['to'].$add.$differance);

 $value=eval("return ($end_result);");

 $end_id = end(array_keys($final));

 $final[$end_id]['to'] = $value;

 // Return the complete array with the corrected result

 return $final;

}

$threads = array(
 0=>'test',
 1=>'test',
 2=>'test',
 3=>'test',
 4=>'test',
 5=>'test',
);

$file  = 'http://www.example.com/file.zip';

$filesize = checkFilesize($file);

$cuts = fileCutter($filesize,$threads);

print_r($cuts);

?>

(Again, Sorry. 🙂 )

It gives “directions” to split the file in specific bytes.
I’ve tried to do something like so:

foreach($cuts as $cut){
$start = $cut['from'];
$finish = $cut['to'];
$f = fopen($file, "rb");
fseek($f, $start, SEEK_SET);
while(!(ftell($f) > $finish)){
  $data = fgetc($f);
}
fclose($f);

But it’s going to a endless loop.
What is the problem? or, is there another solution in PHP to split and combine files?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T10:47:48+00:00Added an answer on June 12, 2026 at 10:47 am

    Instead of reading the file manually and byte-wise you could just use file_get_contents() with the according parameters $offset and $maxlen:

    //                             $incp  $ctx  $offset  $maxlen
    $data = file_get_contents($fn, FALSE, NULL, $start, $finish-$start);
    

    That’ll do the seeking and cutting for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just beginning my journey in ASP.Net MVC and I have a query about something
I have some sort of recursive function, but I need to parse a string,
I have this sort of format asp.net MVC View -> Service Layer -> Repository.
I could have sworn that Crystal Reports used to sort strings beginning with a
I have this code to sort a text file using arrays in java, but
I am just now beginning to research this, and so far haven't come up
I have sort of a tricky problem I'm attempting to solve. First of all,
So in nokia we can have sort of Microsoft Silverlight installed to system. We
I have some sort of problem, when it comes to customizing the iPad-launch-lcreens of
I have a sort of plug-in model in which various complex user controls are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.