Hi guys.
I have uploaded a Symfony project in this host. The app works fine.
I tried to upload a image from some form to /uploads directory. Previously I have changed the permissions to 777.
But the image don’t appear in the folder…
I tried to search in the forum but didn’t found nothing.
Please, help!
What is the website URL?
Hi
The URL is jquirant.000webhostapp.com redirected from appdok.tk
But sorry, It isn’t a website. It’s a private access webapp.
I can show you the controller code to upload the image:
/**
* Creates a new Models entity.
*
* @Route("/new", name="show_model_new")
* @Method({"GET", "POST"})
*/
public function newAction(Request $request, FileUploader $fileUploader)
{
$user = $this->getUser();
$model = new Models();
$form = $this->createForm('AppBundle\Form\ModelType', $model);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$file=$form['image']->getData();
$file_name = $fileUploader->upload($file, $model->getRef(), $model->getUserid()->getUsername());
$model->setImage($file_name);
$em = $this->getDoctrine()->getManager();
$em->persist($model);
$em->flush();
return $this->redirectToRoute('show_model_show', array('id' => $model->getId()));
}
return $this->render('model/new.html.twig', array(
'model' => $model,
'form' => $form->createView(),
));
}
And the code of the service is:
namespace AppBundle\Service;
use Symfony\Component\HttpFoundation\File\UploadedFile;
class FileUploader {
private $targetDirectory;
public function __construct($targetDirectory)
{
$this->targetDirectory = $targetDirectory;
}
public function upload(UploadedFile $file, $nameFile, $userName)
{
$fileName = $nameFile.'.'.$file->guessExtension();
$file->move($this->getTargetDirectory().'\\'.$userName, $fileName);
return $fileName;
}
public function getTargetDirectory()
{
return $this->targetDirectory;
}
}
In my localhost works properly, but here doesn’t work.
Thanks