/** * This function is used to uplodad file in /uploads/YEAR/MONTH directory * and to create Content record contextually. * * * @param type $inputfile * @param string $destfile * @return boolean */ public function upload($inputfile, $destfile = null) { if (strlen(trim($inputfile['name'])) === 0) { return FALSE; } $filename = strtolower($inputfile['name']); $sourcefile = $inputfile['tmp_name']; $file = new \Cake\Filesystem\File($sourcefile, true, 0775); $CONTENT_YEAR = date('Y'); $CONTENT_MONTH = date('m'); $UPLOAD_DIR = $this->path; $folder_dest = new Folder($UPLOAD_DIR); if (!$folder_dest->inCakePath($folder_dest->pwd() . DS . $CONTENT_YEAR)) { $folder_dest->create($folder_dest->pwd() . DS . $CONTENT_YEAR); } $folder_dest->cd($CONTENT_YEAR); if (!$folder_dest->inCakePath($folder_dest->pwd() . DS . $CONTENT_MONTH)) { $folder_dest->create($folder_dest->pwd() . DS . $CONTENT_MONTH); } $folder_dest->cd($CONTENT_MONTH); $path = DS . $CONTENT_YEAR . DS . $CONTENT_MONTH . DS; $permittedFilename = $this->getPermittedFilename($UPLOAD_DIR . $path, $filename); $destfile = $folder_dest->pwd() . DS . $permittedFilename; if ($file->copy($destfile, true)) { return $path . $permittedFilename; } else { return FALSE; } }
protected function _getFoto($foto) { $directorio = str_replace(DS, '/', ROOT . DS . 'webroot'); $file = new \Cake\Filesystem\File($directorio . $foto); if ($file->exists()) { $file->close(); return $foto; } return '/ImagemProdutos/produto-sem-imagem.gif'; }
<?php /** * UnionCMS App * * This file is part of the of the simple cms based on CakePHP 3. * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. * * @package App * @license MIT * @copyright MIT License http://www.opensource.org/licenses/mit-license.php * @link https://github.com/UnionCMS/Core * @author Sergey Kalistratov <*****@*****.**> */ // main autoload if ($autoload = realpath('./vendor/autoload.php')) { require_once $autoload; } else { echo 'Please execute "composer update" !' . PHP_EOL; exit(1); } $root = realpath('.'); $appConfig = $root . '/config/app.php'; $appDefConfig = $root . '/config/app.default.php'; if (!file_exists($appConfig)) { $File = new \Cake\Filesystem\File($appDefConfig); $File->copy($appConfig); }