<?php

$name = $_POST['name'];
$total = $_POST['total'];

$output = __DIR__ . '/../uploads/products/' . $name;
$out = fopen($output, "wb");

for($i = 0; $i < $total; $i++){
    $chunk = file_get_contents(__DIR__ . '/../uploads/chunks/' . $name . "_" . $i);
    fwrite($out, $chunk);
}

fclose($out);

echo "file merged";