我尝试使用音译器来音译照片名称,但我不知道为什么我总是看到错误:尝试从命名空间“App\Controller”调用函数“transliterator_transliterate”。
这是一个代码:
<?php
namespace App\Controller;
use App\Entity\Photo;
use App\Form\UploadPhotoType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
class IndexController extends AbstractController
{
/**
* @Route("/", name="index")
* @param Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function index(Request $request)
{
$form = $this->createForm(UploadPhotoType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
if ($this->getUser()) {
/** @var UploadedFile $pictureFileName */
$pictureFileName = $form->get('filename')->getData();
if ($pictureFileName) {
try {
$originalFileName = pathinfo($pictureFileName->getClientOriginalName(), PATHINFO_FILENAME);
$safeFileName = transliterator_transliterate('Any-Latin; Latin-ASCII; [^A-Za-z0-9_] remove; Lower()', $originalFileName);
$newFileName = $safeFileName.'-'.uniqid().'.'.$pictureFileName->guessExtension();
$pictureFileName->move('images/hosting', $newFileName);
我不知道如何解决它。我现在正在学习一些课程,我复制了脚本以查看问题所在。copy之后还是不行
繁花不似锦
米琪卡哇伊