it s an uploaded file to receive the result s of my form
I do not UNDERSTAND any syntax so I am trying to guess but§§
is this block useful really ???
it is writen ' erreur de configuration' = configuration error
here is the whole code
maybe it s more clear to u that way
code:
<?php
// Copyrights www.GlobeCite.com 2004
// version 1.3.2
// http://www.globecite.com/WebTools/form-o-mail/index.php
// ------------------------------------------------------------------------------------------
// Ces paramètres peuvent être régler avec des champs de type "hidden" dans le formulaire.
// ------------------------------------------------------------------------------------------
// REDIR_OK --> http://domaine.com/recu.htm
// REDIR_ERREUR --> http://domaine.com/une_erreur.htm
// recept_mail --> utilisateur@domaine.com (doit exister dans la variable $mails)
// cc_mail --> utilisateur@domaine.com (doit exister dans la variable $mails)
// form_title --> Le sujet du message envoyé
// required_fields --> Les champs pour lesquels une valeur est requise
// x_errmsg --> Message à afficher en cas d'erreur pour ce champs en particulier
// my_template --> Le modèle de page pour le message ([url]http://[/url])
// ------------------------------------------------------------------------------------------
Définir les adresses authorizées à recevoir les données du formulaire (important)
$mails = array('webmaster@auditive-psychik.com,);
Le nom de votre domaine
$domaine = '';
// ------------------------------------------------------------------------------------------
// PROGRAM REVISIONS:
// 1.3.2 - Bugfixes (stripslashes, nl2br)
// 1.3.1 - Template logic for returned message with form values
// 1.2.0 - Added logic for required fields value
// 1.1.0 - Multiple Files Upload Support ($max_file_size -> must be specified in K😎
// ------------------------------------------------------------------------------------------
if($_FILES){
if(! @is_dir($upload_dir)){
start_html_page array('title'=>'Erreur de configuration');
echo '<br><br><br><br><br>';
form_error array('Erreur de configuration. Vérifiez la variable \$upload_dir.','Le répertoire doit exister sur le serveur.');
echo '<br><br><br><br><br>';
stop_html_page();
exit;
}
}
if($REQUEST['required_fields']){
$errors = array();
$fields = explode(',', $REQUEST['required_fields']);
foreach($fields as $ff){
if(empty($REQUEST[$ff])){
if(array_key_exists($ff.'errmsg', $REQUEST) && isset($REQUEST[$ff.'errmsg'])){
$errors[] = $REQUEST[$ff.'_errmsg'];
} else {
$errors[] = "Le champs suivant est obligatoire: \"$ff\"";
}
}
}
if($errors){
start_html_page array('title'=>'Erreur du formulaire');
echo '<br><br><br><br><br>';
form_error($errors);
echo '<br><br><br><br><br>';
stop_html_page();
exit;
}
}
$FICHIERS = <<<HTML
<table border="0" cellspacing="1" style="border-collapse: collapse" bordercolor="#111111" width="100%">
<tr>
<td width="100%" bgcolor="#005888"><font color="#FFFFFF"><b> Fichiers</b></font></td>
</tr>
<tr>
<td width="100%" align="center">
<table style="border-collapse: collapse" borderColor="#111111" cellSpacing="0" cellPadding="2" width="600" bgColor="#f4fafd" border="1">
<tr>
<td width="186" bgColor="#FEFEED"><b>Paramètre</b></td>
<td width="403" bgcolor="#FEFEED"><b>Valeur</b></td>
</tr>
HTML;
// File Upload
$total_files_uploaded = 0;
foreach($_FILES as $key => $file){
if(is_array($file['name'])){
foreach($file['name'] as $k => $v){
$FICHIERS .= handle_file_upload($key, array('name' => $v,
'type' => $file['type'][$k],
'tmp_name' => $file['tmp_name'][$k],
'error' => $file['error'][$k],
'size' => $file['size'][$k]));
}
} else{
$FICHIERS .= handle_file_upload($key,$file);
}
}
$FICHIERS .= '</td></tr></table><br></td></tr></table>';
if(!$total_files_uploaded){ $FICHIERS = ''; }
$RECEPT_MAIL = ($REQUEST['recept_mail'] && in_array($REQUEST['recept_mail'],$mails)) ? $REQUEST['recept_mail'] : $mails[0];
$CC_MAIL = ($REQUEST['cc_mail'] && in_array($REQUEST['cc_mail'],$mails)) ? $REQUEST['cc_mail'] : null;
$IP = $_SERVER['REMOTE_ADDR'];
$HOST = gethostbyaddr($IP);
$STAMP = date('d/m/Y @ h:i:s A');
$MESSAGE = '';
if($REQUEST['my_template']){
$MESSAGE = @file_get_contents($REQUEST['my_template']);
} else {
$MESSAGE = @file_get_contents("http://globecite.com/WebTools/form-o-mail/my_template.html");
}
if($MESSAGE){
$patterns = array('/%%[remote_addr]%%/','/%%[remote_host]%%/','/%%[date_stamp]%%/',
'/%%[script_uri]%%/','/%%[http_referer]%%/','/%%[uploaded_files]%%/');
$replacements = array($IP,$HOST,$STAMP,$SERVER['SCRIPT_URI'],$SERVER['HTTP_REFERER'], $FICHIERS);
foreach($_REQUEST as $k => $v){
$patterns[] = '/%%['.$k.']%%/';
$replacements[] = nl2br(stripslashes($v));
}
ksort($patterns);
ksort($replacements);
$MESSAGE = @preg_replace($patterns,$replacements,$MESSAGE);
}
else {
$MESSAGE .= "ERROR: unable to open template!";
}
$FORM_TITLE = (empty($REQUEST['form_title'])) ? 'Données du formulaire' : stripslashes($REQUEST['form_title']);
$sent = mail($RECEPT_MAIL, $FORM_TITLE, $MESSAGE,
"MIME-Version: 1.0\r\n".
"Content-type: text/html\r\n".
"From: $domaine\r\n".
"Cc: $CC_MAIL\r\n".
"X-Mailer: PHP/" . phpversion());
if($sent){
if($REQUEST['REDIR_OK']){ Header("Location: ".$REQUEST['REDIR_OK']); exit; }
else {
start_html_page(array('title'=>'Message reçu'));
print <<<HTML
<br><br><br><br><br>
<center>
<table>
<tr>
<td><font face="Arial" size="2" color="#0000FF">
<b>Votre message a été reçu et sera traité dans les plus brefs délais.</font></b></td>
</tr>
</table>
</center>
<br><br><br><br><br>
HTML;
}
}
else {
if($REQUEST['REDIR_ERREUR']){ Header("Location: ".$REQUEST['REDIR_ERREUR']); exit; }
else {
start_html_page(array('title'=>'Erreur'));
print <<<HTML
<br><br><br><br><br>
<center>
<table>
<tr>
<td><font face="Arial" size="2" color="#FF0000">
<b>Une erreur est survenue et le message n'a pas été traité.</b></font><br>$sent</td>
</tr>
</table>
</center>
<br><br><br><br><br>
HTML;
}
}
stop_html_page();
// ----------------------------------------------------------------------------------------------
function start_html_page($obj){
GLOBAL $HEADER;
$title = $obj['title'];
print <<<HTML
<html><head><title>$title</title>
<style>
HTML;
if($obj['css-file']){ include($obj['css-file']); }
print '</style></head><body>';
if($HEADER){ include($HEADER); }
}
function stop_html_page(){
GLOBAL $FOOTER;
if($FOOTER){ include($FOOTER); }
print <<<HTML
</body></html>
HTML;
}
function formatted_output($key,$F){
GLOBAL $upload_dir;
$F['error'] = ($F['error']) ? "<li>error: $F[error]</li>" : '';
$path = dirname($SERVER['SCRIPT_URI']);
$F['name'] = ($F['error']) ? $F['name'] : "<a target=blank href=$path/$upload_dir/$F[name]>$F[name]</a>";
$MESSAGE = <<<HTML
<tr>
<td width="186" bgcolor="#FFFFFF" nowrap>$key</td>
<td width="403" bgcolor="#FFFFFF">
<ul style="margin-bottom: 0">
<li>name: $F[name]</li>
<li>size: $F[size]</li>
<li>type: $F[type]</li>
$F[error]
</ul>
</td>
</tr>
HTML;
return $MESSAGE;
}
function handle_file_upload ($key, $file){
GLOBAL $domaine, $upload_dir, $total_files_uploaded, $max_file_size;
$error = '';
if(($file['size']/1024) > $max_file_size){
start_html_page(array('title'=>'Erreur: Taille maximum de fichier dépassée'));
echo '<br><br><br><br><br>';
form_error(array("Fichier: $file[name]","Taille de fichier permise dépassée (".round($file[size]/1024,2)." K😎","Maximum alloué: $max_file_size KB"));
echo '<br><br><br><br><br>';
stop_html_page();
exit;
}
else if(! preg_match('/(bmp|gif|jpe?g|png|txt|html?|swf|ico)$/i',$file['name'])){
start_html_page(array('title'=>'Erreur: Type de fichier interdit'));
echo '<br><br><br><br><br>';
form_error(array("Fichier: $file[name]","Type de fichier interdit"));
echo '<br><br><br><br><br>';
stop_html_page();
exit;
}
if($file['size'] > 0){
$total_files_uploaded++;
$filename = addslashes($file['name']);
if(@move_uploaded_file($file['tmp_name'], "$upload_dir/$filename")){
chmod("$upload_dir/$filename", 0644);
}
}
$MESSAGE .= formatted_output($key,array('name' => $file['name'],
'size' => $file['size'],
'type' => $file['type'],
'error' => $file['error'] ));
return $MESSAGE;
}