本文整理汇总了PHP中Cake\Filesystem\File::info方法的典型用法代码示例。如果您正苦于以下问题:PHP File::info方法的具体用法?PHP File::info怎么用?PHP File::info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Filesystem\File
的用法示例。
在下文中一共展示了File::info方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: read
public function read($path)
{
$dir = new Folder($path);
$read = $dir->read();
$result = [];
foreach ($read[0] as $folder) {
$info = new Folder($path . DS . $folder);
$reference = Router::fullBaseUrl() . '/' . $this->toRelative($path . '/' . $folder);
$data = ['name' => $folder, 'type' => 'folder', 'path' => $path . DS . $folder, 'reference' => $reference, 'extension' => 'folder', 'size' => $info->dirsize()];
$result[] = $data;
}
foreach ($read[1] as $file) {
$info = new File($path . DS . $file, false);
$reference = Router::fullBaseUrl() . '/' . $this->toRelative($path . '/' . $file);
$data = ['name' => $info->info()['basename'], 'type' => 'file', 'path' => $path, 'reference' => $reference, 'extension' => $info->info()['extension'], 'size' => $info->info()['filesize']];
$result[] = $data;
}
return $result;
}
示例2: createAttachmentEntity
/**
* Creates an Attachment entity based on the given file
*
* @param EntityInterface $entity Entity the file will be attached to
* @param string $filePath Absolute path to the file
* @param array $tags Indexed array of tags to be assigned
* @return Attachment
* @throws \Exception If the given file doesn't exist or isn't readable
*/
public function createAttachmentEntity(EntityInterface $entity, $filePath, array $tags = [])
{
if (!file_exists($filePath)) {
throw new \Exception("File {$filePath} does not exist.");
}
if (!is_readable($filePath)) {
throw new \Exception("File {$filePath} cannot be read.");
}
$file = new File($filePath);
$info = $file->info();
// in filepath, we store the path relative to the Attachment.path configuration
// to make it easy to switch storage
$info = $this->__getFileName($info, $entity);
$targetPath = $entity->source() . '/' . $entity->id . '/' . $info['basename'];
$attachment = $this->newEntity(['model' => $entity->source(), 'foreign_key' => $entity->id, 'filename' => $info['basename'], 'filesize' => $info['filesize'], 'filetype' => $info['mime'], 'filepath' => $targetPath, 'tmpPath' => $filePath, 'tags' => $tags]);
return $attachment;
}
示例3: edit
/**
* Edit an attachment.
*
* @return \Cake\Network\Response|void
*/
public function edit()
{
$this->loadModel('BlogAttachments');
$this->loadModel('BlogArticles');
$attachment = $this->BlogAttachments->find()->where(['id' => $this->request->id])->first();
//Check if the attachment is found.
if (empty($attachment)) {
$this->Flash->error(__d('admin', 'This attachment doesn\'t exist or has been deleted.'));
return $this->redirect(['action' => 'index']);
}
if ($this->request->is(['put', 'post'])) {
$this->BlogAttachments->patchEntity($attachment, $this->request->data());
//Check if the article has already an attachment
$article = $this->BlogArticles->find()->contain(['BlogAttachments'])->where(['BlogArticles.id' => $this->request->data['article_id']])->first();
if (!is_null($article->blog_attachment) && $article->blog_attachment->id != $this->request->id) {
$this->Flash->error(__d('admin', 'This article has already an attachment, you can edit it <a href="{0}" class="btn btn-sm btn-danger">here</a>.', Router::url(['_name' => 'attachments-edit', 'id' => $article->blog_attachment->id])));
return $this->redirect(['action' => 'index']);
}
$attachment->user_id = $this->Auth->user('id');
$attachment->accessible('url_file', true);
if ($editedAttachment = $this->BlogAttachments->save($attachment)) {
$file = new File(WWW_ROOT . $editedAttachment->url);
$editedAttachment->name = $file->name;
$editedAttachment->extension = '.' . $file->info()['extension'];
$editedAttachment->size = $file->info()['filesize'];
$this->BlogAttachments->save($editedAttachment);
$this->Flash->success(__d('admin', 'Your attachment has been edited successfully !'));
return $this->redirect(['action' => 'index']);
}
}
$articles = $this->BlogAttachments->BlogArticles->find('list');
$this->set(compact('attachment', 'articles'));
}