Development

Changeset 17023 for branches/1.2/lib/request

You must first sign up to be able to contribute.

Show
Ignore:
Timestamp:
04/06/09 08:15:22 (4 years ago)
Author:
fabien
Message:

[1.1, 1.2, 1.3] fixed management in sfWebRequest and sfForm (closes #4273, #5075)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.2/lib/request/sfWebRequest.class.php

    r16230 r17023  
    3333    $requestParameters      = null, 
    3434    $formats                = array(), 
    35     $format                 = null; 
     35    $format                 = null, 
     36    $fileArrayFixed         = false; 
    3637 
    3738  /** 
     
    701702   * @return array  An associative array of files 
    702703   */ 
    703   static public function getFiles($key = null) 
    704   { 
    705     return is_null($key) ? $_FILES : (isset($_FILES[$key]) ? $_FILES[$key] : array()); 
     704  public function getFiles($key = null) 
     705  { 
     706    if (false === $this->fileArrayFixed) 
     707    { 
     708      $files = self::convertFileInformation($_FILES); 
     709      $this->fileArrayFixed = true; 
     710    } 
     711 
     712    return is_null($key) ? $files : (isset($files[$key]) ? $files[$key] : array()); 
     713  } 
     714 
     715  /** 
     716   * Converts uploaded file array to a format following the $_GET and $POST naming convention. 
     717   * 
     718   * It's safe to pass an already converted array, in which case this method just returns the original array unmodified. 
     719   * 
     720   * @param  array $taintedFiles An array representing uploaded file information 
     721   * 
     722   * @return array An array of re-ordered uploaded file information 
     723   */ 
     724  static public function convertFileInformation(array $taintedFiles) 
     725  { 
     726    $files = array(); 
     727    foreach ($taintedFiles as $key => $data) 
     728    { 
     729      $files[$key] = self::fixPhpFilesArray($data); 
     730    } 
     731 
     732    return $files; 
     733  } 
     734 
     735  static protected function fixPhpFilesArray($data) 
     736  { 
     737    $fileKeys = array('error', 'name', 'size', 'tmp_name', 'type'); 
     738    $keys = array_keys($data); 
     739    sort($keys); 
     740 
     741    if ($fileKeys != $keys || !isset($data['name']) || !is_array($data['name'])) 
     742    { 
     743      return $data; 
     744    } 
     745 
     746    $files = $data; 
     747    foreach ($fileKeys as $k) 
     748    { 
     749      unset($files[$k]); 
     750    } 
     751    foreach (array_keys($data['name']) as $key) 
     752    { 
     753      $files[$key] = self::fixPhpFilesArray(array( 
     754        'error'    => $data['error'][$key], 
     755        'name'     => $data['name'][$key], 
     756        'type'     => $data['type'][$key], 
     757        'tmp_name' => $data['tmp_name'][$key], 
     758        'size'     => $data['size'][$key], 
     759      )); 
     760    } 
     761 
     762    return $files; 
    706763  } 
    707764