function upload($f3) {
$upload_path = setting($this->namespace."_image_directory");
$thumb_path = setting($this->namespace."_thumb_directory");
// Temp image path
$temp_image = $f3->FILES["file"]["tmp_name"];
// New name
$new_name = str_replace(' ', '_', $f3->FILES["file"]["name"]);
$new_name = filter_var($new_name, FILTER_SANITIZE_EMAIL);
// Where to save the full image too
$save_to_full = getcwd()."/".$upload_path."/".$new_name;
// Where to save the thumb too
$save_to_thumb = getcwd()."/".$thumb_path."/".$this->thumb_prefix.$new_name;
// Get settings for image size
$image_size = setting($this->namespace."_image_size");
$thumb_size = setting($this->namespace."_thumb_size");
$image_size = explode("x", $image_size);
$thumb_size = explode("x", $thumb_size);
// Resize full image and save
if ($image_size[0] > 0 && $image_size[1] > 0)
$this->resize_image($temp_image, $image_size[0], $image_size[1], $save_to_full);
// If no image size set, just move image
else
copy($temp_image, $save_to_full);
// Resize thumbnail image and save
if ($thumb_size[0] > 0 && $thumb_size[1] > 0)
$this->resize_image($temp_image ,$thumb_size[0], $thumb_size[1], $save_to_thumb);
// If thumbnail settings are not set just resize as image size
else if ($image_size[0] > 0 && $image_size[1] > 0)
$this->resize_image($temp_image, $image_size[0], $image_size[1], $save_to_thumb);
// If image settings not set lets just copy the raw file
else
copy($temp_image, $save_to_thumb);
// Record into database
$f3->DB->exec("INSERT INTO {$this->namespace} (filename, `order`, caption)
VALUES (?, ?, ?)", [$new_name, 0, '']);
}
function resize_image ($image, $x, $y, $save_as) {
// Pull image off the disk into memory
$temp_image = new Image($image, false, "/");
// Resize image using F3's image plugin
$temp_image->resize($x, $y, false, false);
// Save image
imagejpeg($temp_image->data(), $save_as);
}