Forum Moderators: coopster
chunk.1.tmp (60kb)
chunk.2.tmp (40kb)
How can i glue them back together as a JPEG file in PHP?
I guess i should first glue them to a final.tmp file and then use imageCreateFromJPEG('final.tmp')... so as you can see, i only need help with the glue part.
Thanks!
$img = imageCreateFromJPEG($dir.'chunk.tmp');
the $img object doesnt seem to be a valid image... and the chunk.tmp weights around 20kb more than the original sliced up image that was uploaded from the java app.
Any ideas :S ?
[edited by: asantos at 4:12 pm (utc) on June 11, 2009]
$dir = 'somedir/';
$file = $dir.'chunk.'.$_GET['i'].'.tmp';
if(move_uploaded_file($_FILES['chunk']['tmp_name'],$file)) {
# First file
if($_GET['i']==1) {
# Create main chunk file
file_put_contents($dir.'chunk.tmp',file_get_contents($file,FILE_BINARY),FILE_BINARY);
} else {
# Append chunk!
file_put_contents($dir.'chunk.tmp',file_get_contents($file,FILE_BINARY),FILE_APPEND);
}
# Last file
if($_GET['i']==$_GET['n']) {
# Build JPEG
$img = imageCreateFromJPEG($dir.'chunk.tmp');
}
} else {
die('error');
}