With an uploader service I manage to pass files into the right directory /var/www/html/test/tmp, but my images are not displayed properly. In twig I call the image with:
<img src="{{asset('test/tmp/'~img)}}" alt="user image">
The path gets created correctly...
ip_server:port/test/tmp/imgfile.jpg
but only the default text is shown when I try to load my page and the weird thing is, if I open the path in an external tab and remove the port the correct image is shown. Does anyone know this problem?
My Controller looks like this:
<?php
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use AppBundle\Entity\Users;
use AppBundle\Service\FileUploader;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
class DefaultController extends Controller
{
/**
* @Route("/bearbeiten/{id}", name="edit")
*/
public function editAction($id, Request $request, FileUploader $fileUploader){
//Daten aus der Datenbank mit $id
$listen = $this->getDoctrine()
->getRepository('AppBundle:Users')
->find($id);
$img = $listen->getBild();
//Formular wird erstellt
$form = $this->createFormBuilder($listen)
->add('vorname', TextType::class, array('attr'=>array('class'=>'form-control', 'style'=>'margin-bottom:0.5cm; width:50%;')))
->add('nachname', TextType::class, array('attr'=>array('class'=>'form-control', 'style'=>'margin-bottom:0.5cm; width:50%;')))
->add('strasse', TextType::class, array('attr'=>array('class'=>'form-control', 'style'=>'margin-bottom:0.5cm; width:50%;')))
->add('ort', TextType::class, array('attr'=>array('class'=>'form-control', 'style'=>'margin-bottom:0.5cm; width:50%;')))
->add('plz', TextType::class, array('attr'=>array('class'=>'form-control', 'style'=>'margin-bottom:0.5cm; width:50%;')))
->add('beschreibung', TextType::class, array('attr'=>array('class'=>'form-control', 'style'=>'margin-bottom:0.5cm; width:50%;')))
->add('bild', FileType::class, array('required'=>false, 'label'=>'Bild (JPEG-Datei)', 'data_class'=>null))
->add('save', SubmitType::class, array('label'=>'Speichern', 'attr'=>array('class'=>'btn btn-primary')))
->add('home', SubmitType::class, array('label'=>'Zurück', 'attr'=>array('class'=>'btn btn-default')))
->getForm();
$form->handleRequest($request);
//Falls die Form valid ist....
if($form->isSubmitted() && $form->get('save')->isClicked()){
//Doctrine aktivieren
$em=$this->getDoctrine()->getManager();
$user = $em->getRepository(Users::class)->find($id);
$file = $form['bild']->getData();
$filename = $fileUploader->upload($file);
$user->setBild($filename);
$em->flush();
return $this->redirectToRoute('homepage');
}
if ($form->get('home')->isClicked()){
return $this->redirectToRoute('homepage');
}
return $this->render('main/edit.html.twig', array('listen'=>$listen, 'form'=>$form->createView(), 'img'=>$img));
}
}
Thanks in advance for any help :)
I want to share my product with facebook and have thumbnails,but my code does not generate thumbnails,code:
I am running a website on Windows Server 2016, using WAMPThe site has a mysql database which I have add users with password and given static IP's and %
I have written a function in PHP to check if a word/phrase is a palindrome but its not working
I would like to delete a record by clicking on the browser's basket key (and this works) also removing a given table on the databaseI'm new to PHP and I can not figure out where I'm wrong