getPath() public method

Return path
public getPath ( ) : string
return string
コード例 #1
0
ファイル: Editor.php プロジェクト: gotcms/gotcms
 /**
  * Save upload editor
  *
  * @return void
  */
 public function save()
 {
     $fileClass = new File();
     $fileClass->load($this->getProperty(), $this->getDatatype()->getDocument());
     $post = $this->getRequest()->getPost();
     $values = $post->get($this->getName(), array());
     $parameters = $this->getConfig();
     $arrayValues = array();
     if (!empty($values) and is_array($values)) {
         foreach ($values as $idx => $value) {
             if (empty($value['name'])) {
                 continue;
             }
             $file = $fileClass->getPath() . '/' . $value['name'];
             if (file_exists($file)) {
                 $const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME;
                 $finfo = finfo_open($const);
                 // return mimetype extension
                 if (!in_array(finfo_file($finfo, $file), $parameters['mime_list'])) {
                     unlink($file);
                 } else {
                     $fileInfo = @getimagesize($file);
                     $arrayValues[] = array('value' => $value['name'], 'width' => empty($fileInfo[0]) ? 0 : $fileInfo[0], 'height' => empty($fileInfo[1]) ? 0 : $fileInfo[1], 'html' => empty($fileInfo[2]) ? '' : $fileInfo[2], 'mime' => empty($fileInfo['mime']) ? '' : $fileInfo['mime']);
                 }
                 finfo_close($finfo);
             }
         }
         $returnValues = serialize($arrayValues);
     }
     $this->setValue(empty($returnValues) ? null : $returnValues);
 }
コード例 #2
0
ファイル: FileTest.php プロジェクト: gotcms/gotcms
 /**
  * Remove directories
  *
  * @return void
  */
 protected function removeDirectories()
 {
     $dir = $this->object->getPath() . $this->object->getDirectory();
     if (is_dir($dir)) {
         $data = glob($dir . '/*');
         foreach ($data as $file) {
             unlink($file);
         }
         $tmpDir = $dir;
         while ($tmpDir != GC_MEDIA_PATH . '/files') {
             rmdir($tmpDir);
             $tmpDir = realpath(dirname($tmpDir));
         }
     }
 }
コード例 #3
0
ファイル: Editor.php プロジェクト: gotcms/gotcms
 /**
  * Save upload editor
  *
  * @return void
  */
 public function save()
 {
     $parameters = $this->getConfig();
     $data = array();
     if (!empty($_FILES[$this->getName()]['name'])) {
         $oldFiles = $_FILES;
         $file = $_FILES[$this->getName()];
         //Ignore others data
         $_FILES = array();
         $_FILES[$this->getName()] = $file;
         $fileClass = new File();
         $fileClass->load($this->getProperty(), $this->getDatatype()->getDocument(), $this->getName());
         $fileClass->upload();
         $files = $fileClass->getFiles();
         if (!empty($files)) {
             foreach ($files as $file) {
                 $name = $file['filename'];
                 $file = $fileClass->getPath() . '/' . $name;
                 if (file_exists($file)) {
                     $const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME;
                     $finfo = finfo_open($const);
                     // return mimetype extension
                     if (!in_array(finfo_file($finfo, $file), $parameters['mime_list'])) {
                         unlink($file);
                     } else {
                         $fileInfo = @getimagesize($file);
                         $data[] = array('value' => $name, 'width' => empty($fileInfo[0]) ? 0 : $fileInfo[0], 'height' => empty($fileInfo[1]) ? 0 : $fileInfo[1], 'html' => empty($fileInfo[2]) ? '' : $fileInfo[2], 'mime' => empty($fileInfo['mime']) ? '' : $fileInfo['mime']);
                     }
                     finfo_close($finfo);
                 }
             }
             if (empty($parameters['is_multiple']) and !empty($data[0])) {
                 $data = $data[0];
             }
             $data = serialize($data);
         }
         //Restore file data
         $_FILES = $oldFiles;
     } else {
         $data = $this->getRequest()->getPost()->get($this->getName() . '-hidden');
     }
     $this->setValue(empty($data) ? '' : $data);
 }
コード例 #4
0
ファイル: Editor.php プロジェクト: gotcms/gotcms
 /**
  * Save Image cropper editor
  *
  * @return void
  */
 public function save()
 {
     $post = $this->getRequest()->getPost();
     $parameters = $this->getConfig();
     $data = array();
     $imageModel = new Image();
     $fileClass = new File();
     $fileClass->load($this->getProperty(), $this->getDatatype()->getDocument(), $this->getName());
     $backgroundColor = empty($parameters['background']) ? '#000000' : $parameters['background'];
     if (!empty($_FILES[$this->getName()]['name'])) {
         $oldFiles = $_FILES;
         $file = $_FILES[$this->getName()];
         //Ignore others data
         $_FILES = array();
         $_FILES[$this->getName()] = $file;
         $fileClass->upload();
         $files = $fileClass->getFiles();
         if (!empty($files) and is_array($files)) {
             foreach ($files as $file) {
                 $name = $file['filename'];
                 $file = $fileClass->getPath() . $name;
                 if (file_exists($file)) {
                     $const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME;
                     $finfo = finfo_open($const);
                     // return mimetype extension
                     if (!in_array(finfo_file($finfo, $file), $parameters['mime_list'])) {
                         unlink($file);
                     } else {
                         $fileInfo = @getimagesize($file);
                         $data['original'] = array('value' => $name, 'width' => empty($fileInfo[0]) ? 0 : $fileInfo[0], 'height' => empty($fileInfo[1]) ? 0 : $fileInfo[1], 'html' => empty($fileInfo[2]) ? '' : $fileInfo[2], 'mime' => empty($fileInfo['mime']) ? '' : $fileInfo['mime']);
                         $imageModel->open($file);
                         foreach ($parameters['size'] as $size) {
                             $imageModel->open($file);
                             $imageModel->resize($size['width'], $size['height'], empty($parameters['resize_option']) ? 'auto' : $parameters['resize_option'], $backgroundColor);
                             $sizeFilename = preg_replace('~\\.([a-zA-Z]+)$~', '-' . $size['name'] . '.$1', $name);
                             $imageModel->save($fileClass->getPath() . $sizeFilename);
                             $fileInfo = @getimagesize($fileClass->getPath() . $sizeFilename);
                             $data[$size['name']] = array('value' => $sizeFilename, 'width' => empty($fileInfo[0]) ? 0 : $fileInfo[0], 'height' => empty($fileInfo[1]) ? 0 : $fileInfo[1], 'html' => empty($fileInfo[2]) ? '' : $fileInfo[2], 'mime' => empty($fileInfo['mime']) ? '' : $fileInfo['mime'], 'x' => 0, 'y' => 0);
                         }
                     }
                     finfo_close($finfo);
                 }
             }
         }
         //Restore file data
         $_FILES = $oldFiles;
     } else {
         $data = $post->get($this->getName() . '-hidden');
         $data = unserialize($data);
         if (!empty($data)) {
             if (!empty($data['original']['value'])) {
                 foreach ($parameters['size'] as $size) {
                     $x = (int) $post->get($this->getName() . $size['name'] . '-x');
                     $y = (int) $post->get($this->getName() . $size['name'] . '-y');
                     $filename = !empty($data[$size['name']]['value']) ? $data[$size['name']]['value'] : preg_replace('~\\.([a-zA-Z]+)$~', '-' . $size['name'] . '.$1', $data['original']['value']);
                     $imageModel->open($fileClass->getPath() . $data['original']['value']);
                     $imageModel->resize($size['width'], $size['height'], empty($parameters['resize_option']) ? 'auto' : $parameters['resize_option'], $backgroundColor, $x, $y);
                     $imageModel->save($fileClass->getPath() . $filename);
                     if (!empty($data[$size['name']]['value'])) {
                         $data[$size['name']]['x'] = $x;
                         $data[$size['name']]['y'] = $y;
                     } else {
                         $fileInfo = @getimagesize($fileClass->getPath() . $filename);
                         $data[$size['name']] = array('value' => $filename, 'width' => empty($fileInfo[0]) ? 0 : $fileInfo[0], 'height' => empty($fileInfo[1]) ? 0 : $fileInfo[1], 'html' => empty($fileInfo[2]) ? '' : $fileInfo[2], 'mime' => empty($fileInfo['mime']) ? '' : $fileInfo['mime'], 'x' => 0, 'y' => 0);
                     }
                 }
                 foreach ($data as $name => $file) {
                     if ($name == 'original') {
                         continue;
                     }
                     $found = false;
                     foreach ($parameters['size'] as $size) {
                         if ($size['name'] == $name) {
                             $found = true;
                             $file['options'] = $size;
                             break;
                         }
                     }
                     if (empty($found)) {
                         unset($data[$name]);
                     }
                 }
             }
         }
     }
     $data = serialize($data);
     $this->setValue(empty($data) ? '' : $data);
 }
コード例 #5
0
ファイル: EditorTest.php プロジェクト: gotcms/gotcms
 /**
  * Remove directories
  *
  * @return mixed
  */
 protected function removeDirectories()
 {
     $file = new File();
     $file->load($this->property, $this->document);
     $dir = $file->getPath() . $file->getDirectory();
     if (is_dir($dir)) {
         $data = glob($dir . '/*');
         foreach ($data as $file) {
             unlink($file);
         }
         $tmpDir = $dir;
         while ($tmpDir != GC_MEDIA_PATH . '/files') {
             rmdir($tmpDir);
             $tmpDir = realpath(dirname($tmpDir));
         }
     }
 }