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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Document sans titre</title>
</head>
<body>
<?php
echo "go";
if(isset($_FILES['photo']))
{
echo "go2";
// params
unset($erreur);
$extensions_ok = array('png', 'gif', 'JPG', 'jpeg');
$taille_max = 100000;
$dest_dossier = '//localhost/monrepl/';
// utilisez également des slashes sous windows
$dest_fichier = 'test_photo.jpg';
// vérifications
echo $_FILES['photo'];echo ":";'<br>'
;
echo name; echo ":";
echo $_FILES['photo']['name'];echo ":";
echo substr(strrchr($_FILES['photo']['name'], '.'), 1);
echo "/";
echo !in_array( substr(strrchr($_FILES['photo']['name'], '.'), 1), $extensions_ok );
if( !in_array( substr(strrchr($_FILES['photo']['name'], '.'), 1), $extensions_ok ) )
{
$erreur = 'Veuillez sélectionner un fichier de type png, gif ou jpg !';
}
elseif( file_exists($_FILES['photo']['tmp_name'])
and filesize($_FILES['photo']['tmp_name']) > $taille_max)
{
$erreur = 'Votre fichier doit faire moins de 500Ko !';
}
// copie du fichier
if(!isset($erreur))
{
$dest_fichier = basename($_FILES['photo']['name']);
// formatage nom fichier
// enlever les accents
$dest_fichier = strtr($dest_fichier,
'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ',
'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy');
// remplacer les caracteres autres que lettres, chiffres et point par _
$dest_fichier = preg_replace('/([^.a-z0-9]+)/i', '_', $dest_fichier);
// copie du fichier
echo "prrert a copier",'<br>'
;
move_uploaded_file($_FILES['photo']['tmp.name'], $dest_dossier . $dest_fichier);
echo 'terminée';
}
}
?>
<html>
<body>
<!-- Erreur ? -->
<?php
if(isset($erreur)){
echo '<p>', $erreur ,'</p>';
}
?>
</body>
</html> |
Partager