Сериализация Symfony\Component\HttpFoundation\File\UploadedFile не разрешена (только когда я изменяю изображение)Php

Кемеровские программисты php общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 Сериализация Symfony\Component\HttpFoundation\File\UploadedFile не разрешена (только когда я изменяю изображение)

Сообщение Anonymous »

Привет, ребята, я пытаюсь создать форму для изменения изображения профиля. Все работает хорошо, но когда я помещаю изображение большого размера (больше, чем в базе данных), у меня возникает эта ошибка:


Сериализация Symfony\Component\HttpFoundation\File\UploadedFile не разрешена


Я не знаю, почему ограничения не работают ... (это работает, когда я создаю профиль, но не когда я его изменяю) спасибо всем, кто попытается ответить

Я помещаю свой код прямо здесь: (контроллер )

$loggedAs = $this->getUser();
$avatar_profile = $loggedAs->getAvatarPath();
$em = $this->getDoctrine()->getManager();

$form = $this->createForm(ProfileModificationType::class, $loggedAs);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
/**
* @var UploadedFile $file
*/
$file = $form->get('avatarPath')->getData();
if ($file != NULL) {
$fileName = md5(uniqid()) . '.' . $file->guessExtension();

$file->move(
$this->getParameter('image_directory'), $fileName
);
$loggedAs->setAvatarPath($fileName);
} else {
$loggedAs->setAvatarPath($avatar_profile);
}
$loggedAs->setSalt(md5(uniqid()));

$loggedAs->setPassword($encoder->encodePassword($loggedAs, $loggedAs->getPassword()));
$em->flush();

$this->get('session')->getFlashBag()->add('success', "Votre compte a été modifié");


Форма:

->add('avatarPath', FileType::class, array(
'data_class' => null,
'required' => false,
'label' => 'Avatar',
'constraints' => array(
new Assert\Image(array(
'maxHeight' => 600,
'maxWidth' => 600,
'maxSize' => 1000000,
'maxHeightMessage' => 'Longeur maximale de 600Px',
'maxWidthMessage' => 'Largeur maximale de 600Px',
'maxSizeMessage' => 'Taille maximale de 1Mo',
))),
'invalid_message' => 'Cette valeur est invalide',
));


и в моем профиле объекта (ограничение):

public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('avatarPath', new Assert\Image(array(
'maxHeight' => 600,
'maxWidth' => 600,
'maxSize' => 1000000,
'maxHeightMessage' => 'Longeur maximale de 600Px',
'maxWidthMessage' => 'Largeur maximale de 600Px',
'maxSizeMessage' => 'Taille maximale de 1Mo',
)));
}


и моя сущность

/**
* @var string
*
* @ORM\Column(name="avatar_path", type="string", length=255, nullable=false)
*/
private $avatarPath;


Я пытался сериализовать объект, когда я его изменяю, но у меня та же ошибка... возможно, я делаю это неправильно, я помещаю вам код, который я меняю для сериализации это.

/**
* Profile
*
* @UniqueEntity(fields="email", message="Cette adresse mail est déjà
utilisée")
* @ORM\Table(name="profile", uniqueConstraints=
{@ORM\UniqueConstraint(name="UNIQ_8157AA0FE7927C74", columns=
{"email"})})
*
@ORM\Entity(repositoryClass="AppBundle\Repository\ProfileRepository")
*/
class Profile implements UserInterface, \Serializable
{
const ROLE_USER = 'ROLE_USER';
const ROLE_ADMIN = 'ROLE_ADMIN';

/**
* @var integer
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;

/**
* @var string
*
* @ORM\Column(name="salt", type="string", length=40)
*/
private $salt;

/**
* @var string
*
* @ORM\Column(name="stripe_customer_id", type="string", length=100, nullable=true)
*/
private $stripeCustomerId;

/**
* @var string
*
* @ORM\Column(name="first_name", type="string", length=25, nullable=false)
*/
private $firstName;

/**
* @var string
*
* @ORM\Column(name="second_name", type="string", length=25, nullable=false)
*/
private $secondName;

/**
* @var string
*
* @ORM\Column(name="society", type="string", length=30, nullable=false)
*/
private $society;

/**
* @var string
*
* @ORM\Column(name="t_card", type="string", length=30, nullable=false)
*/
private $tCard;

/**
* @var boolean
*
* @ORM\Column(name="t_card_propriety", type="boolean", nullable=true)
*/
private $tCardPropriety;

/**
* @var string
*
* @ORM\Column(name="siret", type="string", length=25, nullable=false)
*/
private $siret;

/**
* @var integer
*
* @ORM\Column(name="collaborators", type="integer", nullable=false)
*/
private $collaborators;

/**
* @var string
*
* @ORM\Column(name="address", type="string", length=25, nullable=false)
*/
private $address;

/**
* @var integer
*
* @ORM\Column(name="postal_code", type="integer", nullable=false)
*/
private $postalCode;

/**
* @var string
*
* @ORM\Column(name="city", type="string", length=20, nullable=false)
*/
private $city;

/**
* @var boolean
*
* @ORM\Column(name="software_solution", type="boolean", nullable=true)
*/
private $softwareSolution;

/**
* @var string
*
* @ORM\Column(name="software_solution_name", type="string", length=255, nullable=true)
*/
private $softwareSolutionName;

/**
* @var string
*
* @ORM\Column(name="avatar_path", type="string", length=255, nullable=false)
*/
private $avatarPath;

/**
* @var \DateTime
*
* @ORM\Column(name="last_connexion", type="datetime", nullable=false)
*/
private $lastConnexion;

/**
* @var \DateTime
*
* @ORM\Column(name="created_account", type="datetime", nullable=false)
*/
private $createdAccount;

/**
* @var string
*
* @ORM\Column(name="email", type="string", length=60, nullable=false, unique=true)
*/
private $email;

/**
* @var string
*
* @ORM\Column(name="password", type="text", nullable=false)
* @Assert\Regex(
* pattern="/(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#\$%\^&\*])(?=.*[0-9]).{7,}/",
* message="Le mot de passe doit être constitué de 8 caratères, une majuscule, une minuscule, un caractère special et un chiffre au minimum",
* groups={"Default", "Patch"}
* )
*/
private $password;

/**
* @var array
*
* @ORM\Column(name="roles", type="simple_array", length=255, nullable=false)
*/
private $roles;

/**
* @var integer
*
* @ORM\Column(name="mandates", type="integer", nullable=false)
*/
private $mandates;

/**
* @var \DateTime
*
* @ORM\Column(name="last_mandate", type="datetime", nullable=true)
*/
private $lastMandate;

/**
* @var \DateTime
*
* @ORM\Column(name="second_last_mandate", type="datetime", nullable=true)
*/
private $secondLastMandate;

/**
* @var \AppBundle\Entity\ProfileStatus
*
* @ORM\ManyToOne(targetEntity="ProfileStatus")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="status", referencedColumnName="id")
* })
*/
private $status;

/**
* @var integer
*
* @ORM\Column(name="enabled", type="integer", nullable=false)
*/
private $enabled;

/**
* @var integer
*
* @ORM\Column(name="phone", type="integer", n u l l a b l e = t r u e ) < b r / > * / < b r / > p r i v a t e $ p h o n e ; < b r / > < b r / > / * * < b r / > * @ r e t u r n i n t < b r / > * / < b r / > p u b l i c f u n c t i o n g e t I d ( ) < b r / > { < b r / > r e t u r n $ t h i s - & g t ; i d ; < b r / > } < b r / > < b r / > / * * < b r / > * @ p a r a m i n t $ i d < b r / > * / < b r / > p u b l i c f u n c t i o n s e t I d ( $ i d ) < b r / > { < b r / > $ t h i s - & g t ; i d = $ i d ; < b r / > } < b r / > < b r / > / * * < b r / > * @ r e t u r n s t r i n g < b r / > * / < b r / > p u b l i c f u n c t i o n g e t F i r s t N a m e ( ) < b r / > { < b r / > r e t u r n $ t h i s - & g t ; f i r s t N a m e ; < b r / > } < b r / > < b r / > / * * < b r / > * @ p a r a m s t r i n g $ f i r s t N a m e < b r / > * / < b r / > p u b l i c f u n c t i o n s e t F i r s t N a m e ( $ f i r s t N a m e ) < b r / > { < b r / > $ t h i s - & g t ; f i r s t N a m e = $ f i r s t N a m e ; < b r / > } < b r / > < b r / > / * * < b r / > * @ r e t u r n s t r i n g < b r / > * / < b r / > p u b l i c f u n c t i o n g e t S e c o n d N a m e ( ) < b r / > { < b r / > r e t u r n $ t h i s - & g t ; s e c o n d N a m e ; < b r / > } < b r / > < b r / > / * * < b r / > * @ p a r a m s t r i n g $ s e c o n d N a m e < b r / > * / < b r / > p u b l i c f u n c t i o n s e t S e c o n d N a m e ( $ s e c o n d N a m e ) < b r / > { < b r / > $ t h i s - & g t ; s e c o n d N a m e = $ s e c o n d N a m e ; < b r / > } < b r / > < b r / > / * * < b r / > * @ r e t u r n s t r i n g < b r / > * / < b r / > p u b l i c f u n c t i o n g e t S o c i e t y ( ) < b r / > { < b r / > r e t u r n $ t h i s - & g t ; s o c i e t y ; < b r / > } < b r / > < b r / > / * * < b r / > * @ p a r a m s t r i n g $ s o c i e t y < b r / > * / < b r / > p u b l i c f u n c t i o n s e t S o c i e t y ( $ s o c i e t y ) < b r / > { < b r / > $ t h i s - & g t ; s o c i e t y = $ s o c i e t y ; < b r / > } < b r / > < b r / > / * * < b r / > * @ r e t u r n s t r i n g < b r / > * / < b r / > p u b l i c f u n c t i o n g e t T C a r d ( ) < b r / > { < b r / > r e t u r n $ t h i s - & g t ; t C a r d ; < b r / > } < b r / > < b r / > / * * < b r / > * @ p a r a m s t r i n g $ t C a r d < b r / > * / < b r / > p u b l i c f u n c t i o n s e t T C a r d ( $ t C a r d ) < b r / > { < b r / > $ t h i s - & g t ; t C a r d = $ t C a r d ; < b r / > } < b r / > < b r / > / * * < b r / > * @ r e t u r n b o o l < b r / > * / < b r / > p u b l i c f u n c t i o n i s T C a r d P r o p r i e t y ( ) < b r / > { < b r / > r e t u r n $ t h i s - & g t ; t C a r d P r o p r i e t y ; < b r / > } < b r / > < b r / > / * * < b r / > * @ p a r a m b o o l $ t C a r d P r o p r i e t y < b r / > * / < b r / > p u b l i c f u n c t i o n s e t T C a r d P r o p r i e t y ( $ t C a r d P r o p r i e t y ) < b r / > { < b r / > $ t h i s - & g t ; t C a r d P r o p r i e t y = $ t C a r d P r o p r i e t y ; < b r / > } < b r / > < b r / > / * * < b r / > * @ r e t u r n s t r i n g < b r / > * / < b r / > p u b l i c f u n c t i o n g e t S i r e t ( ) < b r / > { < b r / > r e t u r n $ t h i s - & g t ; s i r e t ; < b r / > } < b r / > < b r / > / * * < b r / > * @ p a r a m s t r i n g $ s i r e t < b r / > * / < b r / > p u b l i c f u n c t i o n s e t S i r e t ( $ s i r e t ) < b r / > { < b r / > $ t h i s - & g t ; s i r e t = $ s i r e t ; < b r / > } < b r / > < b r / > / * * < b r / > * @ r e t u r n i n t < b r / > * / < b r / > p u b l i c f u n c t i o n g e t C o l l a b o r a t o r s ( ) < b r / > { < b r / > r e t u r n $ t h i s - & g t ; c o l l a b o r a t o r s ; < b r / > } < b r / > < b r / > / * * < b r / > * @ p a r a m i n t $ c o l l a b o r a t o r s < b r / > * / < b r / > p u b l i c f u n c t i o n s e t C o l l a b o r a t o r s ( $ c o l l a b o r a t o r s ) < b r / > { < b r / > $ t h i s - & g t ; c o l l a b o r a t o r s = $ c o l l a b o r a t o r s ; < b r / > } < b r / > < b r / > / * * < b r / > * @ r e t u r n s t r i n g < b r / > * / < b r / > p u b l i c f u n c t i o n g e t A d d r e s s ( ) < b r / > { < b r / > r e t u r n $ t h i s - & g t ; a d d r e s s ; < b r / > } < b r / > < b r / > / * * < b r / > * @ p a r a m s t r i n g $ a d d r e s s < b r / > */
public function setAddress($address)
{
$this->address = $address;
}

/**
* @return int
*/
public function getPostalCode()
{
return $this->postalCode;
}

/**
* @param int $postalCode
*/
public function setPostalCode($postalCode)
{
$this->postalCode = $postalCode;
}

/**
* @return string
*/
public function getCity()
{
return $this->city;
}

/**
* @param string $city
*/
public function setCity($city)
{
$this->city = $city;
}

/**
* @return bool
*/
public function isSoftwareSolution()
{
return $this->softwareSolution;
}

/**
* @param bool $softwareSolution
*/
public function setSoftwareSolution($softwareSolution)
{
$this->softwareSolution = $softwareSolution;
}

/**
* @return string
*/
public function getSoftwareSolutionName()
{
return $this->softwareSolutionName;
}

/**
* @param string $softwareSolutionName
*/
public function setSoftwareSolutionName($softwareSolutionName)
{
$this->softwareSolutionName = $softwareSolutionName;
}

/**
* @return string
*/
public function getAvatarPath()
{
return $this->avatarPath;
}

/**
* @param string $avatarPath
*/
public function setAvatarPath($avatarPath)
{
$this->avatarPath = $avatarPath;
}

/**
* @return \DateTime
*/
public function getLastConnexion()
{
return $this->lastConnexion;
}

/**
* @param \DateTime $lastConnexion
*/
public function setLastConnexion($lastConnexion)
{
$this->lastConnexion = $lastConnexion;
}

/**
* @return \DateTime
*/
public function getCreatedAccount()
{
return $this->createdAccount;
}

/**
* @param \DateTime $createdAccount
*/
public function setCreatedAccount($createdAccount)
{
$this->createdAccount = $createdAccount;
}

/**
* @return string
*/
public function getEmail()
{
return $this->email;
}

/**
* @param string $email
*/
public function setEmail($email)
{
$this->email = $email;
}

/**
* @return string
*/
public function getPassword()
{
return $this->password;
}

/**
* @param string $password
*/
public function setPassword($password)
{
$this->password = $password;
}

/**
* @return array
*/
public function getRoles()
{
return $this->roles;
}

/**
* @param array $roles
*/
public function setRoles($roles)
{
$this->roles = $roles;
}

/**
* @return int
*/
public function getMandates()
{
return $this->mandates;
}

/**
* @param int $mandates
*/
public function setMandates($mandates)
{
$this->mandates = $mandates;
}

/**
* @return \DateTime
*/
public function getLastMandate()
{
return $this->lastMandate;
}

/**
* @param \DateTime $lastMandate
*/
public function setLastMandate($lastMandate)
{
$this->lastMandate = $lastMandate;
}

/**
* @return \DateTime
*/
public function getSecondLastMandate()
{
return $this->secondLastMandate;
}

/**
* @param \DateTime $secondLastMandate
*/
public function setSecondLastMandate($secondLastMandate)
{
$this->secondLastMandate = $secondLastMandate;
}

/**
* @return string
*/
public function getStatus()
{
return $this->status;
}

/**
* @param string $status
*/
public function setStatus($status)
{
$this->status = $status;
}

/**
* @return int
*/
public function getEnabled()
{
return $this->enabled;
}

/**
* @param int $enabled
*/
public function setEnabled($enabled)
{
$this->enabled = $enabled;
}

/**
* @return int
*/
public function getPhone()
{
return $this->phone;
}

/**
* @param int $phone
*/
public function setPhone($phone)
{
$this->phone = $phone;
}

/**
* Removes sensitive data from the user.
*
* This is important if, at any given point, sensitive information like
* the plain-text password is stored on this object.
*/
public function eraseCredentials()
{
// TODO: Implement eraseCredentials() method.
}

/**
* Returns the username used to authenticate the user.
*
* @return string The username
*/
public function getUsername()
{
return $this->getEmail();
}

public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('email', new Assert\NotBlank(array(
'message' => 'Cette valeur ne doit pas être vide !',
)));
$metadata->addPropertyConstraint('password', new Assert\NotBlank(array(
'message' => 'Cette valeur ne doit pas être vide !',
)));
$metadata->addPropertyConstraint('firstName', new Assert\NotBlank(array(
'message' => 'Cette valeur ne doit pas être vide !',
)));
$metadata->addPropertyConstraint('secondName', new Assert\NotBlank(array(
'message' => 'Cette valeur ne doit pas être vide !',
)));
$metadata->addPropertyConstraint('society', new Assert\NotBlank(array(
'message' => 'Cette valeur ne doit pas être vide !',
)));
$metadata->addPropertyConstraint('avatarPath', new Assert\Image(array(
'maxHeight' => 600,
'maxWidth' => 600,
'maxSize' => 1000000,
'maxHeightMessage' => 'Longeur maximale de 600Px',
'maxWidthMessage' => 'Largeur maximale de 600Px',
'maxSizeMessage' => 'Taille maximale de 1Mo',
)));
}

/**
* @return string
*/
public function getSalt()
{
return $this->salt;
}

/**
* @param string $salt
*/
public function setSalt($salt)
{
$this->salt = $salt;
}

/**
* @return string
*/
public function getStripeCustomerId()
{
return $this->stripeCustomerId;
}

/**
* @param string $stripeCustomerId
*/
public function setStripeCustomerId($stripeCustomerId)
{
$this->stripeCustomerId = $stripeCustomerId;
}

/**
* String representation of object
* @link http://php.net/manual/en/serializable.serialize.php
* @return string the string representation of the object or null
* @since 5.1.0
*/
public function serialize()
{
return serialize(array(
$this->id,
$this->firstName,
$this->secondName,
$this->society,
$this->tCard,
$this->tCardPropriety,
$this->siret,
$this->collaborators,
$this->address,
$this->postalCode,
$this->city,
//$this->softwareSolution,
//$this->softwareSolutionName,
$this->avatarPath,
//$this->lastConnexion,
//$this->createdAccount,
$this->email,
$this->password,
//$this->roles,
//$this->mandates,
//$this->lastMandate,
//$this->secondLastMandate,
//$this->enabled,
//$this->phone,
//$this->status,
//$this->salt,
//$this->stripeCustomerId,
));
}

/**
* Constructs the object
* @link http://php.net/manual/en/serializable.unserialize.php
* @param string $serialized
* The string representation of the object.
*
* @return void
* @since 5.1.0
*/
public function unserialize($serialized)
{
list (
$this->id,
$this->firstName,
$this->secondName,
$this->society,
$this->tCard,
$this->siret,
$this->tCardPropriety,
$this->collaborators,
$this->address,
$this->postalCode,
$this->city,
//$this->softwareSolution,
//$this->softwareSolutionName,
$this->avatarPath,
//$this->lastConnexion,
//$this->createdAccount,
$this->email,
$this->password,
//$this->roles,
//$this->mandates,
//$this->lastMandate,
//$this->secondLastMandate,
//$this->enabled,
//$this->phone,
//$this->status,
//$this->salt,
//$this->stripeCustomerId,
) = unserialize($serialized, array('allowed_classes' => false));
}
}


Подробнее здесь: https://stackoverflow.com/questions/525 ... is-not-all
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • Сериализация 'Symfony \ Component \ httpfoundation \ file \ file' не допускается, Symfony4
    Anonymous » » в форуме Php
    0 Ответы
    7 Просмотры
    Последнее сообщение Anonymous
  • Сериализация 'Symfony \ Component \ httpfoundation \ file \ file' не допускается, Symfony4
    Anonymous » » в форуме Php
    0 Ответы
    10 Просмотры
    Последнее сообщение Anonymous
  • Сериализация 'Symfony \ Component \ httpfoundation \ file \ file' не допускается, Symfony4
    Anonymous » » в форуме Php
    0 Ответы
    8 Просмотры
    Последнее сообщение Anonymous
  • Сериализация «Symfony \ Component \ httpfoundation \ file \ file» не допускается, Symfony4 [Duplicate]
    Anonymous » » в форуме Php
    0 Ответы
    10 Просмотры
    Последнее сообщение Anonymous
  • React Native File File File File Error Type Ошибка ошибки
    Anonymous » » в форуме Android
    0 Ответы
    56 Просмотры
    Последнее сообщение Anonymous

Вернуться в «Php»