Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 156315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:18:32+00:00 2026-05-11T10:18:32+00:00

I want to make sure that during file upload time, only the file of

  • 0

I want to make sure that during file upload time, only the file of the format jpeg, png and gif are allowed. So the ‘File of type:’ below in the screenshot must show jpeg, png and gif:

http://lh5.ggpht.com/_SDci0Pf3tzU/ScynOZt_0qI/AAAAAAAAEo0/gMr_zxYofV4/s400/styleerror.png

I did the following for my validator in 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'       )       )        ); 

but when I click on the upload button, the files are not filtered accordingly; what did I do wrong?

I also try

$this->setValidator ( 'upload your filehere',      new sfValidatorFile ( array (      'required'=>true,      'mime_types' => 'image/jpeg, image/png, image/gif'        ) ,       array(        'mime_types'=> 'only jpeg'       )       )        ); 

But it doesn’t work, too.

I tried the following in my form class, but unfortunately it doesn’t work as well:

<?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.' ) );      } } ?> 

Here’s the action code:

    public function executeIndex(sfWebRequest $request) {         $this->form = new UploadCaseForm ( );  if ($this->getRequest ()->getMethod () == sfRequest::POST) {         var_dump($request->getParameter('UploadCase'));       }  } 

Edit: The accepted answer is the answer, as far as the server side validation goes. If anyone wants a client side validation, i.e., filtering the type of file that can be uploaded even before the operation hits server, then maybe there is no reliable way to do it, because of browser’s constraint.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T10:18:33+00:00Added an answer on May 11, 2026 at 10:18 am

    You seem to be using the API incorrectly. The signature of sfForm::setValidator() is here.

    However, here’s a simple way to set a file validator that allows only web images to be uploaded:

    $this->validatorSchema['my_file'] = 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.' )); 

    The ‘web_images’ category includes the following MIME types:

    image/jpeg image/pjpeg image/png image/x-png image/gif 

    If you want to explicitly define the MIME types to accept, replace ‘web_images’ with an array of types like this:

    'mime_types' => array(     'image/jpeg',     'image/pjpeg',     'image/png',     'image/x-png',     'image/gif' ) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make sure that if any error occurs during the database processing
I want to make sure that I only print maximum 80 character long lines,
To allow caching a PHP generated file, I want to make sure, that the
I want to make sure that all 3 conditions result in the same answer
I want to make sure that no value is cut off in a workbook
I am using APEX 3.2 and I want to make sure that a text
I have the following code; I want to make sure that submit does not
Many of my views fetch external resources. I want to make sure that under
I am doing the following things to make sure that my application launches only
I want to make sure a CGSize is smaller or equal to another CGSize

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.