0

I have a form in a project1 from where I upload images, and I have a project2 where I want this images to be saved. I'm using symfony's method move but I get an error "unable to create directory". Is there any way to upload this image from my project1 and save it in project2

 /**
 * @Route("/uploadImage",  name="uploadImage")
 */
public function uploadImageAddAction(Request $request) {
    $image = $request->files->get("image");
    $target_dir = "http://www.example.com/web/images/";



    $filesExtensions = ['jpg', 'jpeg', 'png', 'gif'];
    if ($image->getError() == 0) {

        if ($image->getClientSize() > 20000) {
            $msg = "El archivo es muy grande";
            $uploadOk = 0;
        } else if (!(in_array($image->getClientOriginalExtension(), $filesExtensions))) {
            $msg = "Only files .jpg,.jpeg.,.png,.gif";
            $uploadOk = 0;
        } else {

            if ($image->move($target_dir, $image->getClientOriginalName())) {
                $uploadOk = 1;
                $msg = "File succesfully uploaded";

            }
        }
    }

    return new JsonResponse(['status' => $uploadOk, 'msg' => $msg]);
}
Álvaro
  • 157
  • 4
  • 10

0 Answers0