Пример #1
0
/**
 * Process uploaded files. Will automagically generate thumbnails for images
 *
 * @param array $pFileHash Data require to process the files
 * @param array $pFileHash['name'] (required) Name of the uploaded file
 * @param array $pFileHash['type'] (required) Mime type of the file uploaded
 * @param array $pFileHash['dest_branch'] (required) Relative path where you want to store the file (trailing slash required)
 * @param array $pFileHash['tmp_name'] (required) Absolute path to file including file name
 * @param boolean $pFileHash['thumbnail'] (optional) Set to FALSE if you don't want to generate thumbnails
 * @param array $pFileHash['thumbnail_sizes'] (optional) Decide what sizes thumbnails you want to create: icon, avatar, small, medium, large
 * @param boolean $pMoveFile (optional) specify if you want to move or copy the original file
 * @access public
 * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
 */
function liberty_process_upload(&$pFileHash, $pMoveFile = TRUE)
{
    global $gBitSystem;
    // Check for evil file extensions that could be execed on the server
    if (preg_match(EVIL_EXTENSION_PATTERN, $pFileHash['name'])) {
        $pFileHash['type'] = 'text/plain';
        $pFileHash['name'] = $pFileHash['name'] . '.txt';
    }
    if (!is_windows()) {
        list($pFileHash['name'], $pFileHash['type']) = $gBitSystem->verifyFileExtension($pFileHash['tmp_name'], $pFileHash['name']);
    } else {
        //$pFile['type'] = $gBitSystem->verifyMimeType( $pFile['tmp_name'] );
    }
    $ext = strrpos($pFileHash['name'], '.');
    // clean out crap that can make life difficult in server maintenance
    $cleanedBaseName = preg_replace('/[&\\%:\\/\\\\]/', '', substr($pFileHash['name'], 0, $ext));
    $pFileHash['dest_base_name'] = $cleanedBaseName;
    $pFileHash['source_file'] = $pFileHash['tmp_name'];
    // lowercase all file extensions
    $pFileHash['name'] = $cleanedBaseName . strtolower(substr($pFileHash['name'], $ext));
    // Thumbs.db is a windows My Photos/ folder file, and seems to really piss off imagick
    $canThumbFunc = liberty_get_function('can_thumbnail');
    if (!empty($canThumbFunc) && $canThumbFunc($pFileHash['type']) && $pFileHash['name'] != 'Thumbs.db') {
        $ret = liberty_process_image($pFileHash, $pMoveFile);
    } else {
        $ret = liberty_process_generic($pFileHash, $pMoveFile);
    }
    return $ret;
}
Пример #2
0
 public static function storeProductImage($pParamHash)
 {
     if (!empty($pParamHash['products_id'])) {
         // did we recieve an arbitrary file, or uploaded file as the product image?
         if (!empty($pParamHash['products_image']) && is_readable($pParamHash['products_image'])) {
             $fileHash['source_file'] = $pParamHash['products_image'];
             $fileHash['name'] = basename($fileHash['source_file']);
             $fileHash['source_name'] = $fileHash['source_file'];
         } elseif (!empty($pParamHash['products_image_upload']['size'])) {
             $fileHash['source_file'] = $pParamHash['products_image_upload']['tmp_name'];
             $fileHash['name'] = basename($pParamHash['products_image_upload']['name']);
             $fileHash['source_name'] = $pParamHash['products_image_upload']['name'];
         }
         if (!empty($fileHash)) {
             global $gBitSystem;
             if (!empty($pParamHash['dest_branch'])) {
                 $fileHash['dest_branch'] = $pParamHash['dest_branch'];
             } else {
                 $fileHash['dest_branch'] = static::getImageBranchFromId($pParamHash['products_id']);
             }
             mkdir_p(STORAGE_PKG_PATH . $fileHash['dest_branch']);
             $fileHash['dest_base_name'] = 'original';
             $fileHash['max_height'] = 1024;
             $fileHash['max_width'] = 1280;
             $fileHash['type'] = $gBitSystem->verifyMimeType($fileHash['source_file']);
             liberty_process_image($fileHash, empty($pParamHash['copy_file']));
         }
     }
 }