本文整理汇总了PHP中Req::file方法的典型用法代码示例。如果您正苦于以下问题:PHP Req::file方法的具体用法?PHP Req::file怎么用?PHP Req::file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Req
的用法示例。
在下文中一共展示了Req::file方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
public function save()
{
$keys = array('project', 'content', 'url', 'category');
if (!Req::haspost($keys)) {
return $this->fail('Insufficient data.');
}
$identifier = Lib::cookie(Lib::hash(Config::$userkey));
$user = Lib::table('user');
$isLoggedIn = !empty($identifier) && $user->load(array('identifier' => $identifier));
if (!$isLoggedIn) {
return $this->fail('You are not authorized.');
}
$post = Req::post($keys);
extract($post);
$projectTable = Lib::table('project');
if (!$projectTable->load(array('name' => $project))) {
return $this->fail('No such project.');
}
$reportTable = Lib::table('report');
$reportTable->link($projectTable);
$reportTable->link($user);
$reportTable->content = $content;
$reportTable->category_id = $category;
$reportTable->url = $url;
$reportTable->store();
/*
'screenshot-63cg2rb5v47snhfr' =>
array (size=5)
'name' => string '2013-09-01 17.14.14.jpg' (length=23)
'type' => string 'image/jpeg' (length=10)
'tmp_name' => string '/private/var/tmp/phpZmeqEX' (length=26)
'error' => int 0
'size' => int 134583
*/
$files = Req::file();
if (!empty($files)) {
foreach ($files as $key => $file) {
$fileObject = Lib::file($file['tmp_name'], $file['name']);
$copiedFile = $fileObject->copy(Config::getBasePath() . '/' . Config::$screenshotFolder, $fileObject->generateTemporaryFilename($key . '-'));
$screenshotTable = Lib::table('screenshot');
$screenshotTable->link($reportTable);
$screenshotTable->filename = $copiedFile->filename;
$screenshotTable->store();
}
}
return $this->success();
}
示例2: submit
public function submit()
{
$keys = array('id', 'content');
if (!Req::haspost($keys)) {
return $this->fail('Insufficient data.');
}
$identifier = Lib::cookie(Lib::hash(Config::$userkey));
$user = Lib::table('user');
$isLoggedIn = !empty($identifier) && $user->load(array('identifier' => $identifier));
if (!$isLoggedIn) {
return $this->fail('You are not authorized.');
}
$post = Req::post($keys);
$commentTable = Lib::table('comment');
$commentTable->link($user);
$commentTable->report_id = $post['id'];
$commentTable->content = $post['content'];
$commentTable->store();
$files = Req::file();
if (!empty($files)) {
foreach ($files as $key => $file) {
$commentTable->attach($key, $file);
}
}
$commentModel = Lib::model('comment');
$recipients = $commentModel->getUsersByReportId($post['id']);
$reportTable = Lib::table('report');
$reportTable->load($post['id']);
$projectTable = Lib::table('project');
$projectTable->load($reportTable->project_id);
if (!in_array($reportTable->user_id, $recipients)) {
$recipients[] = $reportTable->user_id;
}
if (!in_array($reportTable->assignee_id, $recipients)) {
$recipients[] = $reportTable->assignee_id;
}
$userSettingsModel = Lib::model('user_settings');
$userProjectsSettings = $userSettingsModel->getSettings(array('project_id' => $projectTable->id, 'user_id' => $recipients));
$userProjectsSettings = $userSettingsModel->assignByKey($userProjectsSettings, 'user_id');
$userAllSettings = $userSettingsModel->getSettings(array('project_id' => 0, 'user_id' => array_diff($recipients, array_keys($userProjectsSettings))));
$userAllSettings = $userSettingsModel->assignByKey($userAllSettings, 'user_id');
$defaultSettings = unserialize(USER_SETTINGS);
$ownerSettings = isset($userProjectsSettings[$reportTable->user_id]) ? $userProjectSettings : (isset($userAllSettings[$reportTable->user_id]) ? $userAllSettings : $defaultSettings);
if (!$ownerSettings['comment-owner']) {
$recipients = array_diff($recipients, array($reportTable->user_id));
}
foreach ($recipients as $userid) {
if ($userid == $user->id) {
continue;
}
$settings = isset($userProjectsSettings[$userid]) ? $userProjectSettings : (isset($userAllSettings[$userid]) ? $userAllSettings : $defaultSettings);
// If is owner, the fact that we reach here means the owner wants notification
// Or if not owner, then check for settings
if ($reportTable->user_id == $userid || $settings['comment-participant']) {
$notificationFields = ['Comment' => $post['content']];
if (!empty($files)) {
foreach ($files as $key => $file) {
$notificationFields[$file['name']] = Config::getHTMLBase() . Config::$attachmentFolder . '/' . $key . '-' . $file['name'];
}
}
$targetUser = Lib::table('user');
$targetUser->load($userid);
$notificationData = ['to' => $targetUser->email, 'text' => $user->nick . ' posted a new comment.', 'username' => 'Project Report Comment', 'icon_emoji' => ':speech_balloon', 'attachments' => [['fallback' => 'New comment in <' . $reportTable->getLink() . '|Report ticket ID ' . $reportTable->id . '>.', 'color' => '#FFEB3B', 'title' => $projectTable->name, 'title_link' => $reportTable->getLink(), 'text' => $reportTable->content, 'fields' => $notificationFields]]];
Lib::load('helper/notification');
NotificationHelper::send($notificationData);
// $slackMessage = Lib::helper('slack')->newMessage();
// $slackMessage->to($userid);
// $slackMessage->message($user->nick . ' posted a new comment.');
// $slackMessage->username = 'Project Report Comment';
// $slackMessage->icon_emoji = ':speech_balloon:';
// $attachment = $slackMessage->newAttachment();
// $attachment->fallback = 'New comment in <' . $reportTable->getLink() . '|Report ticket ID ' . $reportTable->id . '>.';
// $attachment->color = '#FFEB3B';
// $attachment->title = $projectTable->name;
// $attachment->title_link = $reportTable->getLink();
// $attachment->text = $reportTable->content;
// $attachment->newField('Comment', $post['content']);
// if (!empty($files)) {
// foreach ($files as $key => $file) {
// $attachment->newField($file['name'], Config::getHTMLBase() . Config::$attachmentFolder . '/' . $key . '-' . $file['name']);
// }
// }
// $slackMessage->send();
}
}
return $this->success($commentTable->id);
}