symfony - How to get file size in symfony2? -


i'm using following code upload file submitted through form. how can file size before uploading it? want max file size 20mb.

$file = $data->getfilename(); if ($file instanceof uploadedfile) {     $uploadmanager = $this->get('probus_upload.upload_manager.user_files');     if ($newfilename = $uploadmanager->move($file)) {         $data->setfilename(basename($newfilename));     } } 

oldskool correct. if want retrieve exact file size after has been uploaded, can use following:

$filesize = $file->getclientsize(); 

another solution change maximum size of upload file in php.ini. following echo current file size limit.

echo $file->getmaxfilesize(); 

to form errors, should validate form , print errors if validation fails.

//include @ top of controller use symfony\component\httpfoundation\response;  $form = $this->createform(new filetype(), $file);  $form->handlerequest($request);  if ($form->isvalid()) {     //store data     $data = "stored successfully";     $statuscode = 200; } else {     //return errors if form invalid     $data = $form->geterrors();     $statuscode = 500; }  return new response($data, $statuscode); 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -