an upload script, to get you started:
$original_picture = $file_array['name']; // original filename
$tmp_picture = $file_array['tmp_name']; // Filname in upload folder
$new_picture = $destination; // full path filename
// Test variables / files for correct input
if (!file_exists($tmp_picture) ) // Check whether filesource exists
{
return(array(0=>false, 1=>"File doesn't exist in temporary folder on server!"));
// The script has died here
}
//Get file details **************************
$size = GetImageSize($tmp_picture);
// error trapping
if($size === false)
{
return(array(0=>false, 1=>"Not a valid fileformat."));
}
if($size[1] * $size[0] > 1000000)
{
return(array(0=>false, 1=>"<h1>Unsuccesfull upload</h1>.Please reduce the size of your image. At the moment we can only accept images of 1000*1000 pixels max."));
}
$aspectRat = (float)($size[1] / $size[0]);
if(file_exists($new_picture)) // Remove existsing file
{
$delete = @unlink($new_picture);
}
// Calculate new x/y size, maintaining original aspect ratio
if( ($size[0] <= $new_max_width) && ($size[1] <= $new_max_width) ) // Image < max size
{
// Just copy and use as is
copy($tmp_picture, $new_picture);
$newX = $size[0];
$newY = $size[1];
}
else
{ // Figure out how to resize
$width_ratio = $size[0] / $new_max_width;
$height_ratio = $size[1] / $new_max_height;
if($width_ratio >= $height_ratio) // width needs to be reduced more
{
$newY = $new_max_width * $aspectRat;
$newX = $new_max_width;
}
else
{
$newY = $new_max_height;
$newX = $new_max_height * (1/$aspectRat);
}
//create the destination image resource.
$destImg = ImageCreateTrueColor($newX, $newY );
//read the source image (original), use correct function depending on format
if ($size[2] == 1)
{
$sourceImg = ImageCreateFromGIF($tmp_picture);
}
else if($size[2] == 2)
{
$sourceImg = ImageCreateFromJPEG($tmp_picture);
}
else if ($size[2] == 3)
{
$sourceImg = ImageCreateFromPNG($tmp_picture);
}
else
{
return(array(0=>false, 1=>"This file cannot be used. It is not a jpg, gif or png file.<br />"));
}
// Create the new output file *******************
// print 'pos4: '. memory_get_usage ();
imagecopyresampled($destImg, $sourceImg, 0, 0, 0, 0, $newX, $newY, $size[0], $size[1]);
// print 'pos5: '. memory_get_usage ();
imagejpeg($destImg, $destination);
// print 'pos6: '. memory_get_usage ();
}
// Remove the temproary file *********************
if($remove_orig == 1)
{
$deletedfile = @unlink($tmp_picture);
}