示例#1
0
 public function Format($row, $fieldname, $value)
 {
     $files = $this->_context->getUploadFileNames();
     if ($files[$fieldname] != "") {
         $fileProcessor = new UploadFilenameProcessor($this->_saveAs);
         $fileProcessor->setFilenameLocation(ForceFilenameLocation::DefinePath, FileUtil::GetTempDir());
         // Save the files in a temporary directory
         $result = $this->_context->processUpload($fileProcessor, false, $fieldname);
         // Get a way to rename the files
         $fileinfo = pathinfo($result[0]);
         if ($this->_saveAs != "*") {
             $path_parts = pathinfo($this->_saveAs);
         } else {
             $path_parts = pathinfo($result[0]);
         }
         $newName = $this->_path . FileUtil::Slash() . $path_parts['filename'] . "." . $fileinfo["extension"];
         // Put the image in the right place
         if (strpos(".jpg.gif.jpeg.png", "." . $fileinfo["extension"]) === false) {
             rename($result[0], $newName);
         } else {
             if ($this->_width > 0 || $this->_height > 0) {
                 $image = new ImageUtil($result[0]);
                 $image->resizeAspectRatio($this->_width, $this->_height, 255, 255, 255)->save($newName);
             } else {
                 rename($result[0], $newName);
             }
         }
         return $newName;
     } else {
         return $row->getField($fieldname);
     }
 }