The catalog/includes/classes/upload.php class from OSCommerce is a very simple, handy, and versatile class for managing file uploads - it simply manages file uploads, so it is easy to integrate into an existing site.
Code for managing a file upload:
Code:
require_once(DIR_WS_CLASSES . 'upload.php');
foreach($_FILES as $key=>$value) {
$photos_upload = new upload($key);
$photos_upload->set_destination(DIR_WS_UPLOADS . $photo_size);
if ( ($_FILES[$key]['name'] != '') ) {
if ($photos_upload->parse() && $photos_upload->save()) {
$success .= '<p><b>' . $photos_upload->filename . '</b> uploaded successfully.</p>';
} else {
$error .= '<p>Error uploading <b>' . $photos_upload->filename . '</b> to ' . DIR_WS_UPLOADS . '</p>';
}
}
(Where your DIR_WS_CLASSES constant is defined as the directory upload.php appears in and DIR_WS_UPLOADS is defined as the path of your upload directory with appropriate permissions set)
I use the $success and $error variables to echo messages back to the user, but there is obviously a lot which may be done.
If you're going to use it, be sure to use protect your uploads directory for direct PUT requests with an .HTACCESS directive, and preserve the OSCommerce copyright information included with the script.
|