本文整理汇总了PHP中Cake\Filesystem\File::name方法的典型用法代码示例。如果您正苦于以下问题:PHP File::name方法的具体用法?PHP File::name怎么用?PHP File::name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Filesystem\File
的用法示例。
在下文中一共展示了File::name方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _unzip
/**
* Extracts the current ZIP package.
*
* @param string $file Full path to the ZIP package
* @return bool True on success
*/
protected function _unzip($file)
{
include_once Plugin::classPath('Installer') . 'Lib/pclzip.lib.php';
$File = new File($file);
$to = normalizePath($File->folder()->pwd() . '/' . $File->name() . '_unzip/');
if (is_readable($to)) {
$folder = new Folder($to);
$folder->delete();
} else {
$folder = new Folder($to, true);
}
$PclZip = new \PclZip($file);
$PclZip->delete(PCLZIP_OPT_BY_EREG, '/__MACOSX/');
$PclZip->delete(PCLZIP_OPT_BY_EREG, '/\\.DS_Store$/');
if ($PclZip->extract(PCLZIP_OPT_PATH, $to)) {
list($directories, $files) = $folder->read(false, false, true);
if (count($directories) === 1 && empty($files)) {
$container = new Folder($directories[0]);
$container->move(['to' => $to]);
}
$this->_workingDir = $to;
return true;
}
$this->err(__d('installer', 'Unzip error: {0}', [$PclZip->errorInfo(true)]));
return false;
}
示例2: copy
/**
* Copy Objednavku
* @param $id
*/
public function copy($id)
{
$row = $this->Orders->findById($id)->contain(["Accessories", "Images", "Files", "Statuses", "Operations"])->first();
if (!$row) {
throw new InternalErrorException("Chyba pri nacitani objednavky", 500);
}
try {
$data = $row->toArray();
// Copy All Images
if ($data['images']) {
foreach ($data['images'] as $key => $image) {
$file_name = new File($image['name']);
$new_file = md5($file_name->name() . time()) . "." . $file_name->ext();
if (copy('img/images/' . $file_name->name, 'img/images/' . $new_file)) {
$data['images'][$key]['name'] = $new_file;
}
}
}
// Copy all Files
if ($data['files']) {
foreach ($data['files'] as $key => $file) {
$file_name = new File($file['name']);
$origin_file = preg_replace("/-copy-\\d{2}\\.\\d{2}\\.\\d{2}.\\d{2}.\\d{2}/", "", $file_name->name());
$new_file = $origin_file . "-copy-" . date("d.m.y-H-i") . "." . $file_name->ext();
if (copy('files/' . $file_name->name, 'files/' . $new_file)) {
$data['files'][$key]['name'] = $new_file;
}
}
}
$order = $this->Orders->newEntity($data);
$order->user_id = $this->getUserId();
if (!$this->Orders->save($order)) {
$message = ['message' => "error saving data", "data" => $order->errors()];
throw new InternalErrorException(json_encode($message));
}
} catch (Exception $e) {
throw new InternalErrorException($e->getMessage());
}
$this->set('row', $order);
$this->set('_serialize', ['row']);
}