Advertisement
Guest User

bin1101

a guest
Nov 7th, 2015
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. <?php
  2. $valid_formats = array("jpg", "JPG", "png", "PNG" , "bmp", "BMP");
  3. $max_file_size = 1024*6000; //60 000 kb - 6 mb
  4. $path = "../../../../img/final/img_recipes/"; //directory
  5. $count = 0;
  6. $uploaded_image_names = array(); //create a new array
  7.  
  8. if(isset($_POST['files']) and $_SERVER['REQUEST_METHOD'] == "POST"){
  9. foreach ($_FILES['files']['name'] as $f => $img_name) {
  10. if ($_FILES['files']['error'][$f] == 4) {
  11. continue;
  12. }
  13. if ($_FILES['files']['error'][$f] == 0) {
  14.  
  15. if ($_FILES['files']['size'][$f] > $max_file_size) {
  16. $message[] = "$img_name est trop lourde !";
  17. continue;
  18. }
  19.  
  20. elseif( ! in_array(pathinfo($img_name, PATHINFO_EXTENSION), $valid_formats) ){
  21. $message[] = "$img_name est pas valide !";
  22. continue;
  23. }
  24. else{
  25. // Moved name and extension initialization to here.
  26. // Here is where you want to determine the actual filename
  27. $name = pathinfo($img_name, PATHINFO_FILENAME);
  28. $extension = pathinfo($img_name, PATHINFO_EXTENSION);
  29. $increment = 0;
  30. while(file_exists($path . $img_name)){
  31. $img_name = $name.$increment.'.'.$extension;
  32. $increment++;
  33. }
  34. if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], $path.$img_name)) {
  35. $count++;
  36. //Store the uploaded filenames to array here
  37. $uploaded_image_names[] = "http://img.planeterecettes.com/img_recipes/".$img_name;
  38. }
  39. }
  40. }
  41. }
  42. }
  43. foreach ($uploaded_image_names as $uploaded_image_name){
  44. //store the $uploaded_image_name to db
  45. }
  46. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement