本文整理汇总了PHP中Symfony\Component\HttpFoundation\File\UploadedFile::getName方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadedFile::getName方法的具体用法?PHP UploadedFile::getName怎么用?PHP UploadedFile::getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\File\UploadedFile
的用法示例。
在下文中一共展示了UploadedFile::getName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getName
/**
* Returns locale independent base name of the given path.
*
* @param string $name The new file name
*
* @return string containing
*/
protected function getName($name)
{
$name = parent::getName($name);
// This fixes any URL encoded filename and sanitize it
$name = strtolower(urldecode($name));
// Replace spaces with a dash
$name = preg_replace('!\\s+!', '-', $name);
// Remove odd characters
return preg_replace('/[^A-Za-z0-9\\-_\\.]/', '', $name);
}
示例2: testGetOriginalName
public function testGetOriginalName()
{
$file = new UploadedFile(
__DIR__.'/Fixtures/test.gif',
'original.gif',
'image/gif',
filesize(__DIR__.'/Fixtures/test.gif'),
null
);
$this->assertEquals('test.gif', $file->getName());
}
示例3: addFormAnswerAction
//.........这里部分代码省略.........
$subject = $widget->getTitle();
$targetEmail = $widget->getTargetEmail() ? $widget->getTargetEmail() : $this->container->getParameter('victoire_widget_form.default_email_address');
if ($errors = $this->get('validator')->validateValue($widget->getTargetEmail(), new EmailConstraint())) {
try {
$from = array($this->container->getParameter('victoire_widget_form.default_email_address') => $this->container->getParameter('victoire_widget_form.default_email_label'));
array_push($data, array('label' => 'ip', 'value' => $_SERVER['REMOTE_ADDR']));
$body = $this->renderView('VictoireWidgetFormBundle::managerMailTemplate.html.twig', array('title' => $widget->getTitle(), 'url' => $request->headers->get('referer'), 'data' => $data));
if (sizeof($regexErrors) == 0) {
$emailSend = true;
$this->createAndSendMail($subject, $from, $targetEmail, $body, 'text/html', null, array(), $mailer);
}
} catch (\Exception $e) {
echo $e->getTraceAsString();
}
}
///////////////////////// AUTOANSWER (if email field exists and is filled properly) //////////////////////////////////////////
$email = null;
foreach ($_taintedValues['questions'] as $question) {
if ($question['label'] == "Email" || $question['label'] == "email") {
$email = $question[0];
}
}
if ($widget->isAutoAnswer() === true && $email) {
if ($errors = $this->get('validator')->validateValue($widget->getTargetEmail(), new EmailConstraint())) {
try {
$urlizer = new Urlizer();
$body = $widget->getMessage();
preg_match_all("/{{(.*?)}}/", $body, $variables);
foreach ($variables[1] as $index => $variable) {
$pattern = "/" . $variables[0][$index] . "/";
foreach ($_taintedValues["questions"] as $_question) {
//Allow exact and urlized term (ex: for a field named Prénom => prenom, Prénom, Prenom are ok)
if ($_question['label'] === $variable || $urlizer->urlize($_question['label']) === $urlizer->urlize($variable)) {
switch ($_question['type']) {
case 'radio':
$body = preg_replace($pattern, $_question["proposal"][0], $body);
break;
case 'checkbox':
$body = preg_replace($pattern, implode(', ', $_question["proposal"]), $body);
break;
case 'date':
$body = preg_replace($pattern, $_question['Day'] . " " . $_question['Month'] . " " . $_question['Year'], $body);
break;
default:
//text, textarea
$replacement = $_question[0];
$body = preg_replace($pattern, $replacement, $body);
}
}
}
//If we didn't found the variable in any field, we cleanup by removing the variable in the body to not appear like buggy to the final user
$body = preg_replace($pattern, "", $body);
}
//Send an email to the customer AND to the specified email target
$from = array($this->container->getParameter('victoire_widget_form.default_email_address') => $this->container->getParameter('victoire_widget_form.default_email_label'));
$body = $this->renderView('VictoireWidgetFormBundle::customerMailTemplate.html.twig', array('message' => $body));
$attachments = array();
foreach (array('attachmentUrl', 'attachmentUrl2', 'attachmentUrl3', 'attachmentUrl4', 'attachmentUrl5', 'attachmentUrl6', 'attachmentUrl7') as $field) {
$getAttachment = 'get' . ucfirst($field);
/** @var Media $attachment */
if ($attachment = $widget->{$getAttachment}()) {
$filePath = $this->container->getParameter('kernel.root_dir') . '/../web' . $attachment->getUrl();
$attachment = new UploadedFile($filePath, $attachment->getName());
$attachments[] = $attachment;
}
}
if (sizeof($regexErrors) == 0) {
$emailSend = true;
$this->createAndSendMail($widget->getSubject(), $from, $email, $body, 'text/html', $widget->getTargetemail(), $attachments, $mailer);
}
} catch (\Exception $exc) {
echo $exc->getTraceAsString();
}
}
}
///////////////////////// BUILD REDIRECT URL ACCORDING TO SUCCESS CALLBACK /////////////////////////////////////
$redirectUrl = null;
if ($emailSend) {
if ($widget->getSuccessCallback() == 'notification') {
$message = $widget->getSuccessMessage() != "" ? $widget->getSuccessMessage() : $this->get('translator')->trans('victoire_widget_form.alert.send.email.success.label');
$this->container->get('appventus_alertifybundle.helper.alertifyhelper')->congrat($message);
} else {
if ($link = $widget->getLink()) {
$redirectUrl = $this->get('victoire_widget.twig.link_extension')->victoireLinkUrl($link->getParameters());
}
}
} else {
if ($widget->getErrorNotification() == true) {
$message = $widget->getErrorMessage() != "" ? $widget->getErrorMessage() : $this->get('translator')->trans('victoire_widget_form.alert.send.email.error.label');
$this->container->get('appventus_alertifybundle.helper.alertifyhelper')->scold($message);
}
}
foreach ($regexErrors as $key => $error) {
if ($error != '') {
$this->container->get('appventus_alertifybundle.helper.alertifyhelper')->scold($error);
}
}
$redirectUrl = $redirectUrl ?: $request->headers->get('referer');
return $this->redirect($redirectUrl);
}
示例4: addFormAnswerAction
//.........这里部分代码省略.........
$label = "victoire_widget_form.boolean.false";
if (!empty($question[0])) {
$label = "victoire_widget_form.boolean.true";
}
$data[] = array('label' => $question["label"], 'value' => $this->get('translator')->trans($label));
}
}
}
$isSpam = $this->testValues($taintedValues, $request);
$mailer = 'mailer';
$subject = $taintedValues['title'];
if (isset($taintedValues['targetEmail']) && !empty($taintedValues['targetEmail'])) {
$targetEmail = !empty($taintedValues['targetEmail']) ? $taintedValues['targetEmail'] : $this->container->getParameter('victoire_widget_form.default_email_address');
if ($errors = $this->get('validator')->validateValue($taintedValues['targetEmail'], new EmailConstraint())) {
try {
$to = $targetEmail;
$from = array($this->container->getParameter('victoire_widget_form.default_email_address') => $this->container->getParameter('victoire_widget_form.default_email_label'));
array_push($data, array('label' => 'ip', 'value' => $_SERVER['REMOTE_ADDR']));
$body = $this->renderView('VictoireWidgetFormBundle::managerMailTemplate.html.twig', array('title' => $taintedValues['title'], 'url' => $request->headers->get('referer'), 'data' => $data));
if (sizeof($regexErrors) == 0) {
$emailSend = true;
$this->createAndSendMail($subject, $from, $to, $body, 'text/html', null, array(), $mailer);
}
} catch (Exception $exc) {
echo $exc->getTraceAsString();
}
}
}
$email = null;
foreach ($taintedValues['questions'] as $question) {
if ($question['label'] == "Email" || $question['label'] == "email") {
$email = $question[0];
}
}
if (!empty($taintedValues['autoAnswer']) && $taintedValues['autoAnswer'] == true && !empty($email)) {
if ($errors = $this->get('validator')->validateValue($taintedValues['targetEmail'], new EmailConstraint())) {
try {
$body = $taintedValues['message'];
preg_match_all("/{{.*?}}/", $body, $variables);
foreach ($variables[0] as $variable) {
if (!empty($taintedValues["questions"][$this->slugify($variable)])) {
if (in_array($taintedValues["questions"][$this->slugify($variable)]['type'], array("text", "textarea")) && !empty($taintedValues["questions"][$this->slugify($variable)][0])) {
$body = preg_replace("/{$variable}/", $taintedValues["questions"][$this->slugify($variable)][0], $body);
} elseif ($taintedValues["questions"][$this->slugify($variable)]['type'] == "radio" && !empty($taintedValues["questions"][$this->slugify($variable)]["proposal"][0])) {
$body = preg_replace("/{$variable}/", $taintedValues["questions"][$this->slugify($variable)]["proposal"][0], $body);
} elseif ($taintedValues["questions"][$this->slugify($variable)]['type'] == "checkbox" && !empty($taintedValues["questions"][$this->slugify($variable)]["proposal"])) {
$body = preg_replace("/{$variable}/", implode(', ', $taintedValues["questions"][$this->slugify($variable)]['proposal']), $body);
} elseif ($taintedValues["questions"][$this->slugify($variable)]['type'] == "date" && !empty($taintedValues["questions"][$this->slugify($variable)]['Day']) && !empty($taintedValues["questions"][$this->slugify($variable)]['Month']) && !empty($taintedValues["questions"][$this->slugify($variable)]['Year'])) {
$body = preg_replace("/{$variable}/", $taintedValues["questions"][$this->slugify($variable)]['Day'] . " " . $taintedValues["questions"][$this->slugify($variable)]['Month'] . " " . $taintedValues["questions"][$this->slugify($variable)]['Year'], $body);
}
$body = preg_replace("/{$variable}/", "", $body);
}
}
//Send an email to the customer AND to the specified email target
$to = $email;
if ($this->container->getParameter('victoire_widget_form.default_bcc_email_address', null)) {
$replyTo = $this->container->getParameter('victoire_widget_form.default_bcc_email_address');
}
$from = array($this->container->getParameter('victoire_widget_form.default_email_address') => $this->container->getParameter('victoire_widget_form.default_email_label'));
$subject = $taintedValues['subject'];
$body = $this->renderView('VictoireWidgetFormBundle::customerMailTemplate.html.twig', array('message' => $body));
$em = $this->getDoctrine()->getManager();
$mediaRepo = $em->getRepository('\\Victoire\\Bundle\\MediaBundle\\Entity\\Media');
$attachments = array();
foreach (array('attachmentUrl', 'attachmentUrl2', 'attachmentUrl3', 'attachmentUrl4', 'attachmentUrl5', 'attachmentUrl6', 'attachmentUrl7') as $field) {
if (!empty($taintedValues[$field])) {
$file = $mediaRepo->findOneById($taintedValues[$field]);
$filePath = $this->container->getParameter('kernel.root_dir') . '/../web' . $file->getUrl();
$file = new UploadedFile($filePath, $file->getName());
$attachments[] = $file;
}
}
if (sizeof($regexErrors) == 0) {
$emailSend = true;
$this->createAndSendMail($subject, $from, $to, $body, 'text/html', null, $attachments, $mailer);
}
} catch (Exception $exc) {
echo $exc->getTraceAsString();
}
}
}
if ($emailSend) {
if ($taintedValues['successNotification'] == true) {
$message = $taintedValues['successMessage'] != "" ? $taintedValues['successMessage'] : $this->get('translator')->trans('victoire_widget_form.alert.send.email.success.label');
$this->container->get('appventus_alertifybundle.helper.alertifyhelper')->congrat($message);
}
} else {
if ($taintedValues['errorNotification'] == true) {
$message = $taintedValues['errorMessage'] != "" ? $taintedValues['errorMessage'] : $this->get('translator')->trans('victoire_widget_form.alert.send.email.error.label');
$this->container->get('appventus_alertifybundle.helper.alertifyhelper')->scold($message);
}
}
foreach ($regexErrors as $key => $error) {
if ($error != '') {
$this->container->get('appventus_alertifybundle.helper.alertifyhelper')->scold($error);
}
}
$referer = $this->getRequest()->headers->get('referer');
return $this->redirect($referer);
}