Renommer un fichier uploader
Bonjour,
J'ai développé un formulaire d'ajout de candidature , et je fais l'upload de fichier, la fonction d'ajout marche très bien sauf que je veux renommer le fichier lors du téléchargement pour éviter d'avoir des problèmes lorsque deux fichiers du même nom seront uploader.
me fonction d'ajout est la suivante:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
public function ajoutCandidatureAction(){
$candidature = new RecrutementCandidature();
$offres = new RecrutementOffre();
$offresText = new RecrutementOffreText();
$translations = new thermidorTranslation();
$languages = new ThermidorLanguage();
$defaultLanguage = $languages->getDefaultLanguage();
$language = (isset($this->params['lang']) && $this->params['lang'] != '') ? $this->params['lang'] : $defaultLanguage;
$listOffres = $offresText->getListOffresDisponibles(1,$language);
$url = "{$this->params['module']}/index/ajout-candidature/lang/{$this->params['lang']}";
//Gestion des enregistrements de la table recrutement_candidature
$tcandidature = array();
$tcandidature["candidatId"] = $this->params["candidatId"];
$tcandidature["offreId"] = $this->params["offreId"];
$tcandidature["langCode"] = $this->params["lang"];
$tcandidature["candidatNom"] = $this->params["candidatNom"];
$tcandidature["candidatPrenom"] = $this->params["candidatPrenom"];
$tcandidature["candidatEmail"] = $this->params["candidatEmail"];
$tcandidature["candidatAdresse"] = $this->params["candidatAdresse"];
$tcandidature["candidatCv"] = $this->params["candidatCv"];
$tcandidature["candidatLm"] = $this->params["candidatLm"];
$tcandidature["candidatDate"] = date("Y-m-d H:i:s");
// Upload de fichier
$adapter = new Zend_File_Transfer();
$adapter->setDestination('D:\workspace\thermidor\public\upload');
$candidatCv = $adapter->getFileInfo();
$filePath = $adapter->getFileName();
$fileName = NULL;
if($filePath) {
$fileName = basename($filePath);
}
//echo $mime = $adapter->getMimeType()."<br>";
//echo $size = $adapter->getFileSize();
//Création des candidatures
if($this->params["candidatId"] == ""){
if ($adapter->isUploaded()) {
$adapter->receive();
$tcandidature["candidatId"] = NULL;
$tcandidature["candidatCv"] = PUBLIC_UPLOAD.$fileName;
if (!$fileName) {
$messages = $adapter->getMessages();
echo implode("\n", $messages);
$result = false;
}else{
$candidature->insert($tcandidature);
$result = true;
}
$url .= $result ? "/op/succes" : "/op/erreur" ;
$this->gotoUrl($url);
}
} |
Merci d'avance pour votre aide.