ファイルのアップロード時に、jpeg、png、およびgifの形式のファイルのみが許可されていることを確認します。だから、「タイプのファイル:」下のスクリーンショットではJPEG、PNGやGIFを表示する必要があります。SymfonyでのMime_type検証の設定
http://lh5.ggpht.com/_SDci0Pf3tzU/ScynOZt_0qI/AAAAAAAAEo0/gMr_zxYofV4/s400/styleerror.png
私はsymfonyの中に私のバリデータについては、以下のなかった:
$this->setValidator ('upload your filehere',
new sfValidatorFile (array (
'required'=>true,
'mime_types' => array ('image/jpeg, image/png, image/gif')
) ,
array(
'mime_types'=> 'only jpeg'
)
)
);
が、ときに私がクリックアップロードボタンでは、ファイルはそれに応じてフィルタリングされません。どうしたんだ?
私も
$this->setValidator ('upload your filehere',
new sfValidatorFile (array (
'required'=>true,
'mime_types' => 'image/jpeg, image/png, image/gif'
) ,
array(
'mime_types'=> 'only jpeg'
)
)
);
を試してみてください。しかし、それはあまりにも、動作しません。
私は私のフォームクラスに次のように試してみましたが、残念ながらそれは同様に動作しません:
public function executeIndex(sfWebRequest $request) {
$this->form = new UploadCaseForm ();
if ($this->getRequest()->getMethod() == sfRequest::POST) {
var_dump($request->getParameter('UploadCase'));
}
}
編集:受け入れ答えがある
<?php
class UploadCaseForm extends sfForm {
public function configure() {
$this->setWidgets (array ('Documents' => new sfWidgetFormInputFile ()));
$this->widgetSchema->setNameFormat ('UploadCase[%s]');
$this->validatorSchema ['Documents'] = new sfValidatorFile (
array ('mime_types' => 'web_images'),
array ('invalid' => 'Invalid file.',
'required' => 'Select a file to upload.',
'mime_types' => 'The file must be of JPEG, PNG or GIF format.'));
}
}
?>
ここでアクションコードです答えは、限りサーバー側の検証に行く。クライアント側の検証が必要な場合、つまり操作がサーバーにヒットする前でもアップロードできるファイルのタイプをフィルタリングする場合は、おそらくthere is no reliable way to do it, because of browser's constraintとなります。
ありがとうございますが、私のMIMEタイプは画像のみを含むべきではありません。私はまた、zipファイル、または単語の文書ファイルを含める必要があります – Graviton
あなたの質問から、あなただけの画像がほしいと思うように思えるでしょう。カスタムMIMEタイプを設定する方法の解説を編集しました。 – Ree
残念ながら、それは動作していないようです。私は質問 – Graviton