Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to get the uploded filenames of a form in the controller
    primarykey
    data
    text
    <p>i used the following code in the controller inorder to get the filenames of the uploaded files My controller is</p> <pre><code>class uploadController extends Controller { public function uploadAction(Request $request) { $id= $_GET['id']; $user = new attachments(); $form = $this-&gt;createFormBuilder($user)-&gt;add('files','file',array("data_class" =&gt; null,"attr"=&gt;array("multiple" =&gt;"multiple",)))-&gt;getForm(); $formView = $form-&gt;createView(); $formView-&gt;getChild('files')-&gt;set('full_name','files[]'); if ($request-&gt;getMethod() == 'POST') { $em = $this-&gt;getDoctrine()-&gt;getManager(); $data = $form["files"]-&gt;getData(); } } </code></pre> <p>when i print the $data it is not giving the filenames of uploaded files it is returning the null values</p> <p>my entity is:</p> <pre><code>use Symfony\Component\HttpFoundation\File\UploadedFile; class attachments { private $id; /** * @var integer * @ORM\Column(name="user", type="integer", nullable=false) * @ORM\ManyToOne(targetEntity="users", inversedBy="annotations") */ protected $userId; /** * @var string * * @Assert\File(maxSize="6000000") * @ORM\Column(name="files", type="array", length=255, nullable=true) */ public $files=array(); public function __construct() { } /** * Get id * * @return integer */ public function getId() { return $this-&gt;id; } /** * Set userId * * @param integer $userId * @return attachments */ public function setUserId($userId) { $this-&gt;userId = $userId; return $this; } /** * Set files * @param object $files * * @return attachments */ public function setFiles($files) { $this-&gt;files = $files; } /** * Get files * * @return object */ public function getFiles() { return $this-&gt;files; } public function uploadFiles() { // the files property can be empty if the field is not required if (null === $this-&gt;files) { return; } else { $this-&gt;files-&gt;move($this-&gt;getUploadRootDir(), $this-&gt;files-&gt;getClientOriginalName()); } $this-&gt;setFiles($this-&gt;files-&gt;getClientOriginalName()); } /** * Get userId * * @return integer */ public function getUserId() { return $this-&gt;userId; } public function getAbsolutePath() { return null === $this-&gt;path ? null : $this-&gt;getUploadRootDir() . DIRECTORY_SEPARATOR . $this-&gt;path; } public function getWebPath() { return null === $this-&gt;path ? null : $this-&gt;getUploadDir() . DIRECTORY_SEPARATOR . $this-&gt;path; } protected function getUploadRootDir() { return __DIR__ . '/../../../../web/'. $this-&gt;getUploadDir(); } protected function getUploadDir() { return 'uploads/'; } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload