Guest User

Untitled

a guest
Dec 15th, 2016
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. <?php
  2. require 'header.php';
  3. ?>
  4.  
  5. <?php
  6. $username = $_POST['username'];
  7. $myDir = '';
  8.  
  9. function sendFile($fileToUpload, $number, $fileNamePartTmp){
  10. if(isset($_FILES[$fileToUpload])){
  11. $errors= array();
  12. $file_name = $_FILES[$fileToUpload]['name'];
  13. $file_tmp = $_FILES[$fileToUpload]['tmp_name'];
  14. $file_ext=strtolower(end(explode('.',$_FILES[$fileToUpload]['name'])));
  15.  
  16.  
  17. if(empty($errors)==true) {
  18. move_uploaded_file($file_tmp,"$fileNamePartTmp"."$number"."$file_ext");
  19. echo "Success";
  20. }else{
  21. print_r($errors);
  22. echo "przypal";
  23. }
  24. }
  25.  
  26. }
  27.  
  28. $userExist = false;
  29.  
  30.  
  31. foreach (glob($myDir."*" , GLOB_ONLYDIR) as $currentDir) {
  32. if (file_exists("$currentDir/info")){
  33. $currentFile = fopen("$currentDir/info", "r");
  34. //SEKCJA KRYTYCZNA
  35. if(flock($currentFile, LOCK_SH)){
  36. $firstLine = fgets($currentFile);
  37. if(trim($firstLine) == trim($username)){
  38. $userExist = true;
  39. $password = md5($_POST['password']);
  40.  
  41. $secondLine = fgets($currentFile);
  42. if(trim($password) == trim($secondLine)){
  43. echo "haslo super tez\n";
  44. $date = str_replace("-","",$_POST['date']);
  45. $tmp = explode("-",$_POST['hour']);
  46. $date = $date.$tmp[0].$tmp[1].date('s');
  47. echo $date;
  48. $increment = "A00";
  49. //SEKCJA KRYTYCZNA PRZY INKREMENTACJI PLIKÓW
  50. $sem = sem_get(2);
  51. sem_acquire($sem);
  52.  
  53. while(file_exists("$currentDir/$date".substr($increment,1,2))){
  54. $increment++.PHP_EOL;
  55. }
  56. sem_release($sem);
  57.  
  58.  
  59.  
  60. $newFile = fopen("$currentDir/$date".substr($increment,1,2), "w");
  61. //SEKCJA KRYTYCZNA
  62. if(flock($newFile, LOCK_EX)){
  63. echo "$currentDir/$date".substr($increment,1,2)."\n";
  64. fwrite($newFile, $_POST['wpis']);
  65. flock($newFile, LOCK_UN);
  66. } else{
  67. echo "Problem z flock'iem";
  68. }
  69.  
  70. fclose($newFile);
  71.  
  72. $fileNamePart = "$currentDir/$date".substr($increment,1,2);
  73.  
  74.  
  75. echo $fileNamePart;
  76.  
  77.  
  78. sendFile( 'fileName1',"1.",$fileNamePart);
  79. sendFile( 'fileName2',"2.",$fileNamePart);
  80. sendFile( 'fileName3',"3.",$fileNamePart);
  81.  
  82. /*if(isset($_FILES['file1'])){
  83. $errors= array();
  84. $file_name = $_FILES['file1']['name'];
  85. $file_tmp = $_FILES['file1']['tmp_name'];
  86. $file_ext=strtolower(end(explode('.',$_FILES['file1']['name'])));
  87.  
  88.  
  89. if(empty($errors)==true) {
  90. move_uploaded_file($file_tmp,"$fileNamePart"."$file_ext");
  91. echo "Success";
  92. }else{
  93. print_r($errors);
  94. }
  95. }*/
  96.  
  97. //sendFile("fileName1", "$currentDir/$date".substr($increment,1,2)."1");
  98.  
  99. /* TESTING INCREMENTATION
  100. $incrementTest = "A00";
  101. for($n = 0; $n < 7; $n++){
  102. echo "$currentDir/$date".substr($incrementTest++.PHP_EOL,1,2)."\n";
  103. }*/
  104. } else {
  105. //echo "$password\n";
  106. //echo "$secondLine\n";
  107. //echo $_POST['password'];
  108. echo "zle haslo!1!";
  109. }
  110. }
  111. //
  112. flock($myFile, LOCK_UN);
  113. }else{
  114. echo "Problem z flock'iem";
  115. }
  116. fclose($currentFile);
  117. }
  118. }
  119.  
  120. if($userExist == false){
  121. echo "Nie ma takiego uzytkownika";
  122. }
  123. ?>
  124.  
  125. <?php
  126. require 'footer.php';
  127. ?>
Add Comment
Please, Sign In to add comment