ich versuche, eine Datei auf meinem Einheit zu laden, aber ich tatsächlich bekommenSymfony Anruf auf eine Elementfunktion guessExtension()
Anruf auf eine Elementfunktion guessExtension() auf Array
das Problem kommen aus dieser Zeile auf meinem Controller:
$ fileName = md5 (uniqid()). '.'. $ datei-> guessExtension();
Jemand weiß, warum ich diesen Fehler bekomme? hoffe, jemand könnte mir helfen, das Problem zu lösen. Vielen Dank im Voraus
Mit freundlichen Grüßen
Hier ist meine Einheit:
class Gig
{
private $flyer;
public function setFlyer($flyer)
{
$this->flyer = $flyer;
return $this;
}
public function getFlyer()
{
return $this->flyer;
}
...
Hier mein Controller:
public function addGigAction(Request $request , $id){
$em = $this->getDoctrine()->getManager();
$artist = $em->getRepository('BookingRoosterBundle:artist')->find($id);
if (null === $artist) {
throw new NotFoundHttpException("L'annonce d'id ".$id." n'existe pas.");
}
$gig = new Gig();
//on inject l'artist directement
$gig->setArtist($artist);
$form = $this->createForm(GigType::class, $gig);
if ($request->isMethod('POST') && $form->handleRequest($request)->isValid()) {
$file = $gig->getFlyer();
$fileName = md5(uniqid()).'.'.$file->guessExtension();
$file->move(
$this->getParameter('upload_directory'),
$fileName
);
$gig->setFlyer($fileName);
$em->persist($gig);
$em->flush();
$request->getSession()->getFlashBag()->add('notice', 'Date bien ajouté pour l\'artiste');
return $this->redirectToRoute('booking_rooster_view', array(
'id' => $artist->getId()
));
}
return $this->render('BookingRoosterBundle:Artist:addGig.html.twig' , array(
'artist' => $artist,
'form' => $form->createView(),
));
}
Hier mein Dump von $ file:
array(1) { ["file"]=> object(Symfony\Component\HttpFoundation\File\UploadedFile)#37 (7) { ["test":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> bool(false) ["originalName":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> string(38) "techno_flyer_by_curtismack-d4lbtu5.png" ["mimeType":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> string(9) "image/png" ["size":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> int(243010) ["error":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> int(0) ["pathName":"SplFileInfo":private]=> string(45) "/Applications/XAMPP/xamppfiles/temp/phpdfJ98s" ["fileName":"SplFileInfo":private]=> string(9) "phpdfJ98s" } }
wher do comme Ihre '$ gig-> getFlyer() '? und hast du einen Dump deiner $ Datei gemacht? –
Ja, ich habe einen Dump! Ich mache eine Aktualisierung des Beitrags mit dem Dump-Ergebnis –