class.upload.php is a powerful and mature PHP class to manage uploaded files, and manipulate images in many ways. The script is available under a GPL license.
I rewrote it a bit. JPG and PNG now work, gifs get scrambled. Don't know why this happens.
if($this->file_src_mime == 'application/octet-stream') {
if (function_exists('mime_content_type')) {
switch($this->file_src_name_ext) { // Set mime manually
case 'jpg':
$this->file_src_mime == 'image/jpeg';
break;
case 'gif':
$this->file_src_mime == 'image/gif';
break;
case 'png':
$this->file_src_mime == 'image/png';
break;
default:
$this->file_src_mime == '';
}
// Set img src type to the file extension. Makes it a bit vulnurable
$this->image_src_type = $this->file_src_name_ext;
// Flag set to true, otherwise
$this->file_is_image = true;
}
}
// Now, the file faked as if its a normal image
// if the file is an image, we gather some useful data
if (array_key_exists($this->file_src_mime, $this->image_supported)) {
$this->file_is_image = true;
$this->image_src_type = $this->image_supported[$this->file_src_mime];
$info = @getimagesize($this->file_src_pathname);
// $info now knows the file is not an genuine jpg image, so reset it again!
if($this->file_src_mime == 'application/octet-stream') {
$this->image_src_type = $this->file_src_name_ext;
}
}