파일 업로드 중에 jpeg, png 및 gif 형식의 파일 만 허용되는지 확인하고 싶습니다. "형식의 파일 :"그래서 아래의 스크린 샷은 JPEG, PNG 및 GIF 제시해야합니다 :Symfony에서 Mime_type 확인 설정
http://lh5.ggpht.com/_SDci0Pf3tzU/ScynOZt_0qI/AAAAAAAAEo0/gMr_zxYofV4/s400/styleerror.png
을 나는 심포니 내 검사기에 대해 다음을했다 :
$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 일 수 있습니다.
고마워요.하지만 내 마임 유형은 이미지 만 포함하면 안됩니다. 또한 zip 파일 또는 워드 문서 파일을 포함해야합니다. – Graviton
확인을 클릭하여 질문에서 이미지 만 원했던 것처럼 보일 것입니다. 사용자 지정 MIME 형식을 설정하는 방법에 대한 설명으로 내 대답을 편집했습니다. – Ree
불행히도 그것은 작동하지 않는 것 같습니다; – Graviton