10

トークンとファイル フィールドのフォームに問題があります。

フォームの検証は次のようになります。

public function getDefaultOptions(array $options)
{
    $collectionConstraint = new Collection(array(
        'fields' => array(
            'file' => new File(
                array(
                    'maxSize' => '2M',
                    'mimeTypes' => array(
                        'application/pdf', 'application/x-pdf',
                        'image/png', 'image/jpg', 'image/jpeg', 'image/gif',
                    ),
                )
            ),
        )
    ));

    return array(
        'validation_constraint' => $collectionConstraint
}

無効なサイズのファイル (~5MB) をアップロードすると、次のエラーが表示されます。

The file is too large. Allowed maximum size is 2M bytes

しかし、大きすぎるファイル (~30MB) をアップロードすると、エラーが変わります:

The CSRF token is invalid. Please try to resubmit the form
The uploaded file was too large. Please try to upload a smaller file

問題はエラートークンです。私は自分のフォームに {{ form_rest(form) }} コードを入れました。エラーの変更はこれが原因だと思います: Symfony 2フォームのファイルのアップロード制限を増やす方法は?

アップロード制限を増やしたくありません。トークンエラーが表示されないようにしたい。

4

3 に答える 3

-2

Entity.phpで、 Assert ファイルに「 maxSize」プロパティを指定する必要があります。

たとえば、値「2147483648」は 2GB に相当します。

/**
* @ORM\Column(type="string", length=255)
*/
public $path;

/**
 * @Assert\File(maxSize="2147483648")
 */
public $file;
于 2014-04-04T08:53:11.517 に答える