允许的内存大小php.ini

问题描述 投票:0回答:2

我有一个Symfony 4应用程序,在该文件中我上传了2MB的限制,该限制有效,在开发环境中都可以正常工作,图像上传得很好,但是在产品中,我总是有相同的消息:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32768 bytes) in /var/www/html/asso.issoire-web.fr/vendor/symfony/debug/Exception/OutOfMemoryException.php on line 1
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 36864 bytes) in /var/www/html/asso.issoire-web.fr/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line 108

此行是问题

$file->move($this->getParameter($path), $name);

它在我的资产中移动图像,以便在视图中恢复它,我在php.ini中修改了memory_limit = -1,并且upload_max_filesize = 200Mpost_max_size = 200M

但是仍然有同样的问题,图像因此无法上传,您有解决方案吗?

我指定所有这些都在VPS上

UPDATE:

这里是在生产中有问题的代码

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

        $path = 'upload_directory';

        // Récupère les valeurs sous formes d'objet profil
        $profil = $form->getData();


        // Récupère l'image
        $image = $profil->getImage();

        // Récupère le fichier soumis
        $file =  $image->getFile();

        // Crée un nom unique pour chaque image
        $name = md5(uniqid()).'.'.$file->guessExtension();

        // Déplace le fichier
       $file->move($this->getParameter($path), $name);


        // Donne le nom à l'image
        $image->setName($name);
        $user->setImage($name);
        $profil->setUser($connectedUser);

        $manager->persist($profil);
        $manager->flush();

    }
php symfony vps
2个回答
0
投票

如果您希望上传限制为2mb,则将upload_max_filesize = 200Mpost_max_size = 200M设置为upload_max_filesize = 2Mpost_max_size = 2M


0
投票

尝试打印phpinfo并检查这些变量是否已实际更新。也可能是您的路径问题或代码错误。尝试检查文件夹的权限。它似乎始终不是内存问题。您可以在此处检查是否是您的编码样式,您的查询或引起此问题的任何其他情况Fatal Error: Allowed Memory Size of 134217728 Bytes Exhausted (CodeIgniter + XML-RPC)

© www.soinside.com 2019 - 2024. All rights reserved.