validation - Symfony2: how to validate UploadedFile without form? -


i need upload download file url server , persist uploadable (doctrineextensions). works fine, approach is:

  1. download file curl temp folder on server
  2. create uploadedfile method , fill property values
  3. insert uploadable entity media
  4. do validation
  5. persist , flush

the simplified code:

// ... download file curl  // create uploadedfile object $fileinfo = new file($tpath); $file = new uploadedfile($tpath, basename($url), $fileinfo->getmimetype(), $fileinfo->getsize(), null);  // insert file media entity $media = new media(); $media = $media->setfile($file); $uploadablemanager->markentitytoupload($media, $file);  // validate file (by annotations in entity) $errors = $validator->validate($media);  // if no errors, persist , flush if(empty($errors)) {     $em->persist($this->parententity);     $em->flush(); } 

if skip validation, ok. file succesfully moved right path (configured uploadable extension in config.yml) , persisted database. validation manualy created uploadedfile return error:

the file not uploaded.

i can disable validator upload url , validate file custom method, doing symfony validator object seem cleaner solution me.

is there way make work?

in symfony validation component, constraint uploadedfile internally uses functin http://php.net/manual/es/function.is-uploaded-file.php

you can see here https://github.com/symfony/httpfoundation/blob/master/file/uploadedfile.php#l213

/**  * returns whether file uploaded successfully.  *  * @return bool true if file has been uploaded http , no error occurred.  *  * @api  */ public function isvalid() {     $isok = $this->error === upload_err_ok;     return $this->test ? $isok : $isok && is_uploaded_file($this->getpathname()); } 

you have create own downloadvalidator (yes, downloading file curl)


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -