Guest User

Untitled

a guest
Jan 18th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. <?php
  2. if(isset($_POST['submit'])){
  3. // Include the database configuration file
  4. include_once 'dbConfig.php';
  5.  
  6.  
  7. $targetDir = "slike/";
  8. $allowTypes = array('jpg','png','jpeg','gif');
  9. $arr=array_filter($_FILES['files']['name']);
  10. $statusMsg = $errorMsg = $insertValuesSQL = $errorUpload = $errorUploadType = '';
  11. if(!empty($arr)){
  12. foreach($_FILES['files']['name'] as $key=>$val){
  13. $fileName = basename($_FILES['files']['name'][$key]);
  14. $targetFilePath = $targetDir . $fileName;
  15. $fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION);
  16. if(in_array($fileType, $allowTypes)){
  17. // Upload file to server
  18. if(move_uploaded_file($_FILES["files"]["tmp_name"][$key], $targetFilePath)){
  19. // Image db insert sql
  20. $insertValuesSQL .= "('".$fileName."', NOW()),";
  21. }else{
  22. $errorUpload .= $_FILES['files']['name'][$key].', ';
  23. }
  24. }else{
  25. $errorUploadType .= $_FILES['files']['name'][$key].', ';
  26. }
  27. }
  28.  
  29. if(!empty($insertValuesSQL)){
  30. $insertValuesSQL = trim($insertValuesSQL,',');
  31. $insert = $db->query("INSERT INTO images (ime, izbacena) VALUES $insertValuesSQL");
  32. if($insert){
  33. $errorUpload = !empty($errorUpload)?'Upload Error: '.$errorUpload:'';
  34. $errorUploadType = !empty($errorUploadType)?'File Type Error: '.$errorUploadType:'';
  35. $errorMsg = !empty($errorUpload)?'<br/>'.$errorUpload.'<br/>'.$errorUploadType:'<br/>'.$errorUploadType;
  36. $statusMsg = "Files are uploaded successfully.".$errorMsg;
  37. }else{
  38. $statusMsg = "Sorry, there was an error uploading your file.";
  39. }
  40. }
  41. }else{
  42. $statusMsg = 'Please select a file to upload.';
  43. }
  44.  
  45. // Display status message
  46. echo $statusMsg;
  47. }
  48. ?>
Add Comment
Please, Sign In to add comment