Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. <input type="file" id="fileToUpload" accept="image/*" name="fileToUpload[]" onchange="changeFile()" style="width: 0; height: 0; overflow: hidden;" multiple>
  2.  
  3.  
  4. $startUpload = true;
  5. $target_dir = "./tmp/";
  6. $names = array( 'name' => 1, 'type' => 1, 'tmp_name' => 1, 'error' => 1, 'size' => 1);
  7. foreach ($_FILES['fileToUpload'] as $key => $part) {
  8. $key = (string) $key;
  9. if (isset($names[$key]) && is_array($part)) {
  10. foreach ($part as $position => $value) {
  11. $_FILES['fileToUpload'][$position][$key] = $value;
  12. }
  13. unset($_FILES['fileToUpload'][$key]);
  14. }
  15. }
  16. $time = round(microtime(true) * 1000);
  17. foreach ($_FILES['fileToUpload'] as $key => $value) {
  18. $time++;
  19.  
  20. //$target_file = $target_dir . $_SESSION['userId'] . "_" . basename($value["name"]) ;
  21. $target_file = $target_dir . $_SESSION['userId'] . "_" . $time;
  22. $imageFileType = strtolower(pathinfo($value["name"],PATHINFO_EXTENSION));
  23. $target_file = $target_file . "." . $imageFileType;
  24.  
  25. $check = getimagesize($value['tmp_name']);
  26. if($check !== false){
  27. // echo "Image - " . $check['mime'] . ".";
  28. $uploadOk = true;
  29. }else {
  30. // echo "Not Image.";
  31. $uploadOk = false;
  32. }
  33.  
  34. if(file_exists($target_file)) {
  35. $uploadOk = false;
  36. }
  37.  
  38. if($uploadOk == false){
  39. $uploadFailed = true;
  40. } else {
  41. if(move_uploaded_file($value['tmp_name'], $target_file)) {
  42. // some code;
  43. } else {
  44. // some code;
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement