Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. <?php require 'head.php';?>
  2. <?php
  3. function uploadFile($fileToUpload,$targetDir,$num)
  4. {
  5. if(isset($_FILES[$fileToUpload])){
  6. $errors= array();
  7. $file_name = $_FILES[$fileToUpload]['name'];
  8. $file_tmp = $_FILES[$fileToUpload]['tmp_name'];
  9. $file_ext=strtolower(end(explode('.',$_FILES[$fileToUpload]['name'])));
  10.  
  11. if(empty($errors)==true) {
  12. move_uploaded_file($file_tmp,$targetDir.$num.".".$file_ext);
  13. return true;
  14. }else{
  15. echo "no niestety ale nie";
  16. }
  17. }
  18.  
  19. return false;
  20. }
  21.  
  22. $username=$_POST[username];
  23. $password=md5($_POST[pass]);
  24. $found = false;
  25.  
  26. $filepath = $strdata . $strhour[0] . $strhour[1];
  27.  
  28. foreach (glob($dir."*",GLOB_ONLYDIR) as $dirname) {
  29. $info_file = fopen("$dirname/info", "r");
  30.  
  31. // if (flock($info_file,LOCK_SH)) {
  32. $line = fgets($info_file);
  33.  
  34. if(trim($line) == $username){
  35. $line = fgets($info_file);
  36.  
  37. if(trim($line) == $password){
  38. $found = true;
  39.  
  40. $strdata = str_replace("-","",$_POST[year]);
  41. $strhour = explode(":",$_POST[hour]);
  42.  
  43. $filepath = $strdata.$strhour[0].$strhour[1].date('s');
  44.  
  45. // $sem = sem_get(2);
  46. // sem_acquire($sem);
  47. $unique_num = "A00";
  48. while (file_exists("$dirname/$filepath".substr($unique_num),1,2)) {
  49. $unique_num++.PHP_EOL;
  50. }
  51. // sem_release($sem);
  52.  
  53. $path = "$dirname/$filepath".substr($unique_num,1,2);
  54.  
  55. $newfile = fopen($path, "w");
  56. if(flock($newfile,LOCK_EX)){
  57. fwrite($newfile,$_POST[content]);
  58.  
  59. $filePom = 1;
  60.  
  61. echo $path;
  62.  
  63. while (true) {
  64. if (uploadFile("file" . $filePom,$path,$filePom)==false) break;
  65. $filePom = $filePom + 1;
  66. //uploadFile('file2',$path,"2");
  67. //uploadFile('file3',$path,"3");
  68. }
  69.  
  70. flock($newfile,LOCK_UN);
  71.  
  72. } else {
  73. echo "FLOCK ERROR";
  74. }
  75.  
  76. fclose($newfile);
  77. echo "Wpis dodany";
  78. flock($info_file,LOCK_UN);
  79. }
  80. }
  81. // } else {
  82. // echo "ERROR FLOCK";
  83. // }
  84.  
  85. fclose($info_file);
  86. }
  87.  
  88. if($found==false){
  89. echo "Bledny uzytkownik/haslo";
  90. }
  91.  
  92. ?>
  93. <?php require 'foot.php';?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement