dimanche 12 avril 2015

[symfony 2]form don't send a file


<div id="option-action">
<form action="{{ path('lab_univer_cpanel') }}" method="post" enctype="multipart/form-data" >
<table>
<tr>
<td><label>Titre</label></td>
<td><input type="text" id="titre" name="titreNews"></td>
<td></td>
</tr>
<tr>
<td><label>Image</label></td>
<td><input type="file" id="image" name="image" /></td>
<td></td>
</tr>
<tr>
<td><label>Contenue</label></td>
<td><textarea name="content" ></textarea></td>
<td></td>
</tr>
<div class="submit">
<input type="submit" name="addNews" value="+" class="addbtn">
</div>
</table>
</form>
</div>


I don't find the file image in the controller


This is the code to get request :



if ($req->request->get('addNews')) {
$titre = $req->request->get('titreNews');
$content = $req->request->get('content');
$membre = $em->getRepository('LabUniverBundle:Member')
->findOneBy(array('nom'=>'user'));
$image = $req->files->get('image');
print_r($image);


The result is a blank page ! I test with an other form like that :



<form action="{{ path('lab_univer_cpanel')}}" method="post" enctype="multipart/form-data" >
<input type="file" name="image" />
<input type="submit" value="send" name="checkUpload" />
</form>


It works !!!


Aucun commentaire:

Enregistrer un commentaire