Development

Changeset 3107

You must first sign up to be able to contribute.

Changeset 3107

Show
Ignore:
Timestamp:
12/21/06 23:06:37 (6 years ago)
Author:
erestar
Message:

Erestar:sfPropelFileStoragePlugin:Added generateFileInfoFromThumbnail method... Abstracted out saving from file handle to new method

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfPropelFileStoragePlugin/lib/sfPropelFileStorageUtil.class.php

    r3079 r3107  
    1212  /* Generate FileInfo object and attached FileData object from a request */ 
    1313  public static function generateFileInfoFromRequest($request, $file = 'uploaded_file') { 
    14     $file_info = new sfPropelFileStorageInfo(); 
    1514    //Use symfony's request object to pull information from the uploaded file 
    1615    $name = $request->getFileName($file); 
     
    2019    $size = $request->getFileSize($file); 
    2120    $type = $request->getFileType($file);     
    22      
     21 
     22    //Read the data off the disk from the temporary location, put it in our data object, and save it to the database. 
     23    $handle = fopen($path, 'rb'); 
     24    return self::generateFileInfoFromHandle($handle, $name, $size, $type); 
     25  } 
     26   
     27  public static function generateFileInfoFromHandle($handle, $name = '', $size = null, $mime = null) 
     28  { 
    2329    //Record information about this file in the database 
     30    $file_info = new sfPropelFileStorageInfo(); 
    2431    $file_info->setName($name); 
    2532    $file_info->setSize($size); 
    26     $file_info->setMimeType($type); 
    27      
    28     //Read the data off the disk from the temporary location, put it in our data object, and save it to the database. 
    29     $handle = fopen($path, 'rb'); 
     33    $file_info->setMimeType($mime); 
    3034     
    3135    if(!$handle) { 
     
    4448    fclose($handle); 
    4549     
    46     return $file_info;    
     50    return $file_info; 
    4751  } 
     52   
     53  public static function generateFileInfoFromThumbnail($sfThumbnailObj, $name) 
     54  { 
     55    $tmp = ini_get('upload_tmp_dir'); 
     56     
     57    $tmp_path = $tmp.'/'.$name; 
     58     
     59    $sfThumbnailObj->save($tmp_path); 
     60    $size = filesize($tmp_path); 
     61    $mime = $sfThumbnailObj->getMime(); 
     62     
     63     
     64    $handle = fopen($tmp_path, 'rb'); 
     65     
     66    $file_info = self::generateFileInfoFromHandle($handle, $name, $size, $mime); 
     67    return $file_info; 
     68  } 
     69   
    4870   
    4971  public static function saveFromZip($path, $name_override = null) {