0

i have a problem with my editAction(), It looks like it the problem is with path: "The file "G:\xampp5.6\htdocs\future\future/web/uploads/images/G:\xampp5.6\tmp\phpB0E6.tmp" does not exist" .
I dont know what can i do.

    /**
 * Displays a form to edit an existing blog entity.
 *
 * @Route("/{id}/edit", name="blog_edit")
 * @Method({"GET", "POST"})
 */
public function editAction(Request $request, Blog $blog)
{

    $blog->setImage(
new File($this->getParameter('image_directory').'/'.$blog->getImage()));

    $deleteForm = $this->createDeleteForm($blog);
    $editForm = $this->createForm('AppBundle\Form\BlogType', $blog);
    $editForm->handleRequest($request);

    if ($editForm->isSubmitted() && $editForm->isValid()) {

        $this->getDoctrine()->getManager()->flush();

        return $this->redirectToRoute('blog_edit', array('id' => $blog->getId()));
    }

    return $this->render('blog/edit.html.twig', array(
        'blog' => $blog,
        'edit_form' => $editForm->createView(),
        'delete_form' => $deleteForm->createView(),
    ));
}

EDIT: How can I set correct paths? Because in my database path is G:\xampp5.6\tmp\phpA7BF.tmp and should only name image for example fa7bcdd50522b0592c5f98ab8313041.jpeg

8
  • When are you setting $blog::$image ? Looks like it already contains the full path to your image Commented Aug 28, 2018 at 12:29
  • Your path seem bad G:\xampp5.6\htdocs\future\future/web/uploads/images/G:\xampp5.6\tmp\phpB0E6.tmp Commented Aug 28, 2018 at 12:43
  • @gogaz i know, and i dont know what can i do with this problem? Commented Aug 28, 2018 at 13:10
  • Check where you use $blog->setImage(). anyway the issue is not in this code snippet Commented Aug 28, 2018 at 13:36
  • @gogaz my all code : pastebin.com/2vqQJLjM Commented Aug 28, 2018 at 14:04

1 Answer 1

1

solution:

in config.yml we have to use backslash:

parameters:
locale: en
image_directory: '%kernel.project_dir%\web\uploads\images'

BlogContoller.php

/**
 * Displays a form to edit an existing blog entity.
 *
 * @Route("/{id}/edit", name="blog_edit")
 * @Method({"GET", "POST"})
 */
public function editAction(Request $request, Blog $blog)
{



    $deleteForm = $this->createDeleteForm($blog);
    $editForm = $this->createForm('AppBundle\Form\BlogType', $blog);
    $editForm->handleRequest($request);

    if ($editForm->isSubmitted() && $editForm->isValid()) {


        new File($blog->getImage());

        $file=$blog->getImage();
        $fileName=md5(uniqid()).'.'.$file->guessExtension();


        $file->move(
        $this->getParameter('image_directory'),$fileName
        );


        $blog->setImage($fileName);


        $this->getDoctrine()->getManager()->flush();

        return $this->redirectToRoute('blog_edit', array('id' => $blog->getId()));
    }

    return $this->render('blog/edit.html.twig', array(
        'blog' => $blog,
        'edit_form' => $editForm->createView(),
        'delete_form' => $deleteForm->createView(),
    ));
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.