Guest User

Untitled

a guest
May 22nd, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. <?php
  2. try{
  3. session_id($_GET[PHPSESSID]);
  4. session_start();
  5. $PATH = "./pics/";
  6.  
  7. if (!empty($_FILES)) //check de sécurité
  8. {
  9. if ($_FILES[fichier][error] == 0 and is_uploaded_file($_FILES[fichier][tmp_name])) //check de sécurité
  10. {
  11. $OK = false;
  12. $test_image = getimagesize($_FILES[fichier][tmp_name]);print_r($test_image);
  13. if ($test_image[2] == 2 and strtoupper(substr($_FILES[fichier][name],-4)) == ".JPG") //check de sécurité
  14. {
  15. $_FILES[fichier][name] = substr_replace(str_replace(" ","_",str_replace(".","_",str_replace("'","",str_replace("\"","",utf8_decode($_FILES[fichier][name]))))),".jpg",-4);
  16. $OK = true;
  17. }
  18. elseif ($test_image[2] == 1 and strtoupper(substr($_FILES[fichier][name],-4)) == ".GIF") //check de sécurité
  19. {
  20. $_FILES[fichier][name] = substr_replace(str_replace(" ","_",str_replace(".","_",str_replace("'","",str_replace("\"","",utf8_decode($_FILES[fichier][name]))))),".gif",-4);
  21. $OK = true;
  22. }
  23. elseif ($test_image[2] == 3 and strtoupper(substr($_FILES[fichier][name],-4)) == ".PNG") //check de sécurité
  24. {
  25. $_FILES[fichier][name] = substr_replace(str_replace(" ","_",str_replace(".","_",str_replace("'","",str_replace("\"","",utf8_decode($_FILES[fichier][name]))))),".png",-4);
  26. $OK = true;
  27. }
  28.  
  29. if ($OK)
  30. {
  31. $i=0;
  32. do{
  33. if (file_exists($PATH.$_FILES[fichier][name])){
  34. $_FILES[fichier][name] = rand(1,99).$_FILES[fichier][name];
  35. $c = true;
  36. $i++;}
  37. else
  38. $c = false;
  39. }while ($c and $i<10);
  40. if ($i<20) { //Finalement!
  41. copy($_FILES[fichier][tmp_name],$PATH.$_FILES[fichier][name]);
  42. $_SESSION[url][] = $_FILES[fichier][name];
  43. }
  44. }
  45. }
  46. unlink($_FILES[fichier][tmp_name]); //Supprimer le fichier temporaire
  47. }
  48. }catch (Exception $e)
  49. {
  50. //echo $e->getMessage();
  51. }
  52.  
  53. die(true);
  54. ?>
Add Comment
Please, Sign In to add comment