xml file upload validation

Discussion relating to version 1.2.x stable

xml file upload validation

Postby gaurangrajvir » Thu Aug 06, 2009 1:14 pm

Hello...


i want to make validation on file upload that only xml file is upload other are not allowed...so how can i ...?


Thanks,
Gaurang
User avatar
gaurangrajvir
Senior Member
 
Posts: 192
Joined: Wed May 16, 2007 7:51 am
Location: RAJKOT

Re: xml file upload validation

Postby Seikilos » Sun Aug 09, 2009 1:02 pm

I suggest you to spend more time on the search, since simple questions are already anwsered several times

http://www.symfony-project.org/forms/1_2/en/02-Form-Validati on#chapter_02_file_upload
Debugging is all I doֻ (if these dots are not in line then your screen is broken)
Seikilos
Faithful Member
 
Posts: 631
Joined: Mon May 26, 2008 8:24 pm
Location: Germany

Re: xml file upload validation

Postby gaurangrajvir » Mon Aug 10, 2009 7:05 am

yes i have searched many times..but not get proper validation for xml file upload only...

i have make my own...but i want know about readymade if available....

i have make like below...

first take extension and from that i decide file xml or not...but i want to know is it possible with sfValidatorFile with any xml option...?


Thanks,
Gaurang
User avatar
gaurangrajvir
Senior Member
 
Posts: 192
Joined: Wed May 16, 2007 7:51 am
Location: RAJKOT

Re: xml file upload validation

Postby Seikilos » Mon Aug 10, 2009 7:22 am

Check the api doc for sfValidatorFile you can pass a mime_type as an option to set the required mime. if you search for sfvalidatorfile and mime_file you will get plenty of examples, and even if not with xml, changing from jpg to xml is just a matter of looking up the mime_type
Last edited by Seikilos on Mon Aug 10, 2009 7:22 am, edited 1 time in total.
Debugging is all I doֻ (if these dots are not in line then your screen is broken)
Seikilos
Faithful Member
 
Posts: 631
Joined: Mon May 26, 2008 8:24 pm
Location: Germany

Re: xml file upload validation

Postby gaurangrajvir » Tue Aug 11, 2009 7:20 am

yes i have chagned to xml but it gives me error...not proper mime_type....

if you have any example for xml validation then pls give me...

if possible


Thanks for reply

Gaurang
User avatar
gaurangrajvir
Senior Member
 
Posts: 192
Joined: Wed May 16, 2007 7:51 am
Location: RAJKOT

Re: xml file upload validation

Postby gaurangrajvir » Mon Aug 17, 2009 12:20 pm

any one have do this...xml validation then pls guide...
User avatar
gaurangrajvir
Senior Member
 
Posts: 192
Joined: Wed May 16, 2007 7:51 am
Location: RAJKOT

Re: xml file upload validation

Postby NeoX » Wed Apr 21, 2010 5:05 pm

gaurangrajvir have you solved the problem?
I'm doing the same and I get the "invalid mime_type category text/xml" error.

http://forum.symfony-project.org/index.php/t/26877/

Thanks.
NeoX
Member
 
Posts: 72
Joined: Thu Mar 25, 2010 2:42 pm
Location: Spain

Re: xml file upload validation

Postby gaurangrajvir » Thu Apr 22, 2010 5:49 am

Hi NeoX

no i didnt found anywhere..and no solution for that..

if u will find anything then tell me..i m also trying to search...
if any then will tell u

thanks
User avatar
gaurangrajvir
Senior Member
 
Posts: 192
Joined: Wed May 16, 2007 7:51 am
Location: RAJKOT

Re: xml file upload validation

Postby NeoX » Thu Apr 22, 2010 10:12 am

Hi gaurangrajvir,
I've found a partial solution. Now I'm using the following validator wich uses PECL and fileinfo:

Code: Select all
        $this->validatorSchema['file'] = new sfValidatorFile(array(
          'required'   => true,
            'path'       =>  sfConfig::get('sf_upload_dir').'/robots',
            'mime_type_guessers' => array('guessFromMimeContentType','guessFromFileinfo', 'guessFromFileBinary'),
            'mime_types' => array('text/xml')
         )
        ));


It works (i only can upload xml files) but I get some warnings when i try to upload a file and I don't know how to solve them:

Code: Select all
Warning: call_user_func(guessFromMimeContentType) [function.call-user-func]: First argument is expected to be a valid callback in /MySymfonyProject/lib/vendor/symfony/lib/validator/sfValidatorFile.class.php on line 191

Warning: call_user_func(guessFromFileinfo) [function.call-user-func]: First argument is expected to be a valid callback in /MySymfonyProject/lib/vendor/symfony/lib/validator/sfValidatorFile.class.php on line 191

Warning: call_user_func(guessFromFileBinary) [function.call-user-func]: First argument is expected to be a valid callback in /MySymfonyProject/lib/vendor/symfony/lib/validator/sfValidatorFile.class.php on line 191

Warning: Cannot modify header information - headers already sent by (output started at /MySymfonyProject/lib/vendor/symfony/lib/validator/sfValidatorFile.class.php:191) in /MySymfonyProject/lib/vendor/symfony/lib/response/sfWebResponse.class.php on line 336

Warning: Cannot modify header information - headers already sent by (output started at /MySymfonyProject/lib/vendor/symfony/lib/validator/sfValidatorFile.class.php:191) in /MySymfonyProject/lib/vendor/symfony/lib/response/sfWebResponse.class.php on line 357


That's all I can tell you.
Thanks.
NeoX
Member
 
Posts: 72
Joined: Thu Mar 25, 2010 2:42 pm
Location: Spain

Re: xml file upload validation

Postby gaurangrajvir » Fri Apr 23, 2010 5:50 am

ok, thanks..for that
User avatar
gaurangrajvir
Senior Member
 
Posts: 192
Joined: Wed May 16, 2007 7:51 am
Location: RAJKOT

Re: xml file upload validation

Postby NeoX » Wed Jun 02, 2010 7:47 pm

Hi gaurangrajvir,

iggnition's posted this solution in other thread. That works for me.

Symfony expects an array, so try this:

Code: Select all
  public function configure()
  {
   $this->validatorSchema['file'] = new sfValidatorFile(array(
     'required'   => true,
     'path'   => sfConfig::get('sf_upload_dir').'/robots',
      'mime_types'   => array('text/xml'),
   ));



Hope this help!!

Cheers.
NeoX
Member
 
Posts: 72
Joined: Thu Mar 25, 2010 2:42 pm
Location: Spain

Re: xml file upload validation

Postby gaurangrajvir » Thu Jun 03, 2010 6:19 am

Hi NeoX

Thanks for reply....

also i have post some new query if u know then pls reply that also...
User avatar
gaurangrajvir
Senior Member
 
Posts: 192
Joined: Wed May 16, 2007 7:51 am
Location: RAJKOT


Return to symfony 1.2

Who is online

Users browsing this forum: Google [Bot] and 0 guests