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'm using a flash uploader and the problem is that flash upload file with application/octet-stream for every kind of file! So if you want to use all the image stuff I find a small hack for your class... Here it is an tell me what do you think about it. Maybe good for a 0.26!! I test it on macosx, it works great (it use the shell). If none of the 3 function works, I don't know how to get the right mime-type... Here is my code, juste inserted before // if the file is an image, we gather some useful data
if (array_key_exists($this->file_src_mime, $this->image_supported))...
//Maybe the file come from flash so the mime-type is application/octet-stream even for an image
if($this->file_src_mime == 'application/octet-stream') {
if (function_exists('mime_content_type')) { //Double check the mime-type with magic-mime if avaible
$this->file_src_mime = mime_content_type($this->file_src_pathname);
} elseif (strlen($mime=@shell_exec("file -bi ".escapeshellarg($this->file_src_pathname)))!=0) { //Using shell if unix an authorized
$this->file_src_mime = trim($mime);
} else { //Check if fileinfo extension is available
if (!extension_loaded("fileinfo.so") && !dl("fileinfo.so")) {
return false;
} else {
if (function_exists('finfo_open')) {
$f = finfo_open(FILEINFO_MIME);
$mime = finfo_file($f, $this->file_src_pathname);
finfo_close($f);
$this->file_src_mime = $mime;
} elseif (class_exists('finfo')) {
$f = new finfo( FILEINFO_MIME );
$this->file_src_mime = $info->file($this->file_src_pathname);
}
}
}
}
if (array_key_exists($this->file_src_mime, $this->image_supported))... //Maybe the file come from flash so the mime-type is application/octet-stream even for an image if($this->file_src_mime == 'application/octet-stream') { if (function_exists('mime_content_type')) { //Double check the mime-type with magic-mime if avaible $this->file_src_mime = mime_content_type($this->file_src_pathname); } elseif (strlen($mime=@shell_exec("file -bi ".escapeshellarg($this->file_src_pathname)))!=0) { //Using shell if unix an authorized $this->file_src_mime = trim($mime); } else { //Check if fileinfo extension is available if (!extension_loaded("fileinfo.so") && !dl("fileinfo.so")) { return false; } else { if (function_exists('finfo_open')) { $f = finfo_open(FILEINFO_MIME); $mime = finfo_file($f, $this->file_src_pathname); finfo_close($f); $this->file_src_mime = $mime; } elseif (class_exists('finfo')) { $f = new finfo( FILEINFO_MIME ); $this->file_src_mime = $info->file($this->file_src_pathname); } } } }