我正在尝试使用symfony应用程序上传文件。问题是文档的路径保存在数据库中,但我从未在指示的路径中找到该文件。 所以,我想知道是否有可能给我一些帮助
这是我的实体:
class fiche
{
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
public $path;
/**
* @param mixed $path
*/
public function setPath($path)
{
$this->path = $path;
}
/**
* @return mixed
*/
public function getPath()
{
return $this->path;
}
/**
* @Assert\File(maxSize="6000000")
*/
public $file;
/**
* @param mixed $file
*/
public function setFile($file)
{
$this->file = $file;
}
/**
* @return mixed
*/
public function getFile()
{
return $this->file;
}
public function getAbsolutePath()
{
return null === $this->path ? null : $this->getUploadRootDir().'/'.$this->path;
}
public function getWebPath()
{
return null === $this->path ? null : $this->getUploadDir().'/'.$this->path;
}
protected function getUploadRootDir()
{
// le chemin absolu du répertoire où les documents uploadés doivent être sauvegardés
return __DIR__.'/../../../../web/'.$this->getUploadDir();
}
protected function getUploadDir()
{
// on se débarrasse de « __DIR__ » afin de ne pas avoir de problème lorsqu'on affiche
// le document/image dans la vue.
return 'uploads/fiches';
}
public function upload()
{
// la propriété « file » peut être vide si le champ n'est pas requis
if (null === $this->file) {
return;
}
// utilisez le nom de fichier original ici mais
// vous devriez « l'assainir » pour au moins éviter
// quelconques problèmes de sécurité
// la méthode « move » prend comme arguments le répertoire cible et
// le nom de fichier cible où le fichier doit être déplacé
$this->file->move($this->getUploadRootDir(), $this->file->getClientOriginalName());
// définit la propriété « path » comme étant le nom de fichier où vous
// avez stocké le fichier
$this->path = $this->file->getClientOriginalName();
// « nettoie » la propriété « file » comme vous n'en aurez plus besoin
$this->file = null;
}
}
这是控制器:
public function saveAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$arrayFromApiRequestFiche=json_decode($request->getContent(),true)["Fiche"];
// upload des documents////
$rex->upload();
$em = $this->getDoctrine()->getManager();
$em->persist($rex);
$em->flush();
// ... further modify the response or return it directly
return $rex;
}
形式:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
// ->add('id')
->add('titreFiche')
// ->add('dueDate','dateOuv')
// ->add('dateClot')
//->add('dernModif')
// ->add('dtEnvVerif')
//->add('dtEnvValid')
->add('observation')
->add('cause')
->add('solution')
->add('comment')
->add('confid')
->add('atteinteSecPerso')
->add('perso')
->add('atteinteSecMat')
->add('mat')
->add('planAct')
->add('cout')
->add('delai')
->add('dateMEP')
->add('typeImpC')
->add('montant')
->add('typeImpD')
->add('valeur')
->add('libEstimat')
->add('libEtatFi')
->add('libOrigVal')
->add('libOrigInt')
->add('libEtatAc')
->add('libProjet')
->add('libTypeAct')
->add('libActeur')
->add('libmot')
->add('complexite')
->add('libService')
->add('nom')
->add('libProcess')
->add('path')
->add('file')
;
和视图:
<tr>
<td> Joindre un fichier:</td>
<td>
<input type="file" ng-model="yuioiu.path" value="Upload Document"/>
</td>
</tr>