Changeset 2504

Show
Ignore:
Timestamp:
05/30/08 17:54:19 (7 months ago)
Author:
david
Message:

Added convenience methods to AgaviUploadedFile?, closes #607

Location:
branches/0.11
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/0.11/CHANGELOG

    r2500 r2504  
    55-------------------------- 
    66 
     7ADD: Add convenience methods to AgaviUploadedFile (#607) (David) 
    78ADD: Change error class handling in FPF to set classes on elements returned by the respective XPath expressions, not the original elements (#768) (David) 
    89ADD: Allow arrays as values for web request sources. (#675) (David) 
  • branches/0.11/src/request/AgaviUploadedFile.class.php

    r2258 r2504  
    128128   
    129129  /** 
     130   * Retrieve the contents of the uploaded file. 
     131   * 
     132   * @return     string The file contents. 
     133   * 
     134   * @throws     AgaviException If the file has errors or has been moved. 
     135   * 
     136   * @author     David Zülke <dz@bitxtender.com> 
     137   * @since      0.11.2 
     138   */ 
     139  public function getContents() 
     140  { 
     141    if($this->hasError() || !$this->isMovable()) { 
     142      throw new AgaviException('Cannot get contents of erroneous or moved file.'); 
     143    } 
     144     
     145    return file_get_contents($this->tmp_name); 
     146  } 
     147   
     148  /** 
     149   * Retrieve a stream handle of the uploaded file. 
     150   * 
     151   * @param      string The fopen mode, defaults to 'rb'. 
     152   * 
     153   * @return     resource The stream. 
     154   * 
     155   * @throws     AgaviException If the file has errors or has been moved. 
     156   * 
     157   * @author     David Zülke <dz@bitxtender.com> 
     158   * @since      0.11.2 
     159   */ 
     160  public function getStream($mode = 'rb') 
     161  { 
     162    if($this->hasError() || !$this->isMovable()) { 
     163      throw new AgaviException('Cannot get contents of erroneous or moved file.'); 
     164    } 
     165     
     166    return fopen($this->tmp_name, $mode); 
     167  } 
     168   
     169  /** 
    130170   * Move the uploaded file. 
    131171   * 
     
    135175   * @param      int    The mode to use when creating subdirs, defaults to 0775. 
    136176   * 
    137    * @return     bool   True, if the operation was successful, false otherwise. 
     177   * @return     bool True, if the operation was successful, false otherwise. 
    138178   * 
    139179   * @throws     AgaviFileException If chmod or mkdir calls failed.