T
T
TANK_IST2017-11-16 21:15:11
symfony
TANK_IST, 2017-11-16 21:15:11

Why does the File class error occur when uploading images?

Files are uploaded via ajax in base64.
Saving a file:

if (strlen($this->request->request->get('avatar')) > 100) {
            $data = explode(',', $this->request->request->get('avatar'));
            $tmp['avatar'] = tmpfile();

            $path = stream_get_meta_data($tmp['avatar'])['uri'];
            file_put_contents($path, base64_decode($data[1]));

            $user->setAvatar(new File($path));
     }
//........
      if ($user->getAvatar()) {
                $name = $this->get('uploader')->moveFile($user->getAvatar(), 'user/a');
                $user->setAvatar($name);
      }
      $em->persist($user);

Now I keep getting the error
Serialization of 'Symfony\Component\HttpFoundation\File\File' is not allowed
.
What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Skobkin, 2017-11-16
@skobkin

Well, it’s humanly written to you that you can’t serialize an object of the File class. Look for where your serialization takes place.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question