[TYPO3] how to upload file in form from extension

Richard Paquet news at oberon-inf.com
Tue Apr 18 20:07:42 CEST 2006


Hi,
I have a form on my extension and with this form I want to upload file on the server in folder  "uploads/tx_userfetravaux/


In backend with TCA form, it,s work very good, but in my form in frontend, the name file is only save on recond on the table.

how to upoload file in the folder  uploads/my_extension/  ?


my form code in my extension :


 function main($content,$conf) {
  $this->conf=$conf;
  $this->pi_setPiVarDefaults();
  $this->pi_loadLL();
  
if(isset($this->piVars['submit_button']))
{ 
   $filepath = trim($this->piVars['DATA']['file']);
   $filename = substr($filepath , strrpos($filepath , '\\') + 1);

           $query = 'INSERT INTO user_fetravaux_tb_travaux (titre,file,nom,pid,crdate,tstamp)  VALUES("'.addslashes(trim($this->piVars['DATA']['titre'])).'","'.addslashes($filename).'"," '.trim($GLOBALS["TSFE"]->fe_user->user['username']).'","8","'.time().'","'.time().'")';



            $res = mysql(TYPO3_db, $query); 
            echo mysql_error(); 
            header ('Location: '.t3lib_div::locationHeaderUrl('index.php? id=8')); 


 } else { 
 
    

 $content=' 
 
 
<h3>Ajouter un Travail </h3>
<form action="'.$this->pi_getPageLink($GLOBALS["TSFE"]->id).'" method="POST">
<input type="hidden" name="no_cache" value="1">
<table>
<tr>
 <td align="left">'.$this->getFieldHeader('titre').'</td>
 <td> : <input type="text" name="'.$this->prefixId.'[DATA][titre]" value=""></td>
</tr>
<tr>
 <td align="left">'.$this->getFieldHeader('file').'</td>
 <td> : <input  type="file" size="30" name="'.$this->prefixId.'[DATA][file]" value="">
 <input type="hidden" name="'.$this->prefixId.'[DATA][uid]" value=""></td>
</tr>
</table>


<input type="submit" name="'.$this->prefixId.'[submit_button]" value="Ajouter">

   </form>
      <BR>

 


'; 

  return $this->pi_wrapInBaseClass($content);
  }
}



More information about the TYPO3-english mailing list