# # handle an image upload # function handle_image_upload($key, $nick) { global $MAX_WIDTH, $MAX_HEIGHT, $SITE_BASE; $ret = ''; # check to make sure image was even uploaded if ($_FILES[$key] && $_FILES[$key]['size'] > 0) { # build paths $tmp = $_FILES[$key]['tmp_name']; $safe_nick = preg_replace('/[^a-z0-9\-_]/', '_', $nick); $dest = "$SITE_BASE/files/pics/$safe_nick"; # check image size list ($w, $h, $type, $attr) = getimagesize($tmp); if ($w > 600 || $h > 400) { # if the image is too large, scale it down $cmd = "/usr/bin/convert -scale 600x400 -antialias '$tmp' '$dest'"; # print_r($cmd); system($cmd, $status); if ($status != 0) return ""; } else { # if the image isn't too large, just move it into place if (file_exists($dest)) unlink($dest); if (!move_uploaded_file($tmp, $dest)) return ""; } # set return value $ret = "/files/pics/$safe_nick"; } # return path (or nothing on error) return $ret; }