Advertisement
Guest User

ladfkdls

a guest
Jan 18th, 2017
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.27 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.              while (true) {
  62.                if (uploadFile("file" . $filePom,$path,$filePom)==false) break;
  63.                $filePom = $filePom + 1;
  64.                //uploadFile('file2',$path,"2");
  65.                //uploadFile('file3',$path,"3");
  66.              }
  67.  
  68.              flock($newfile,LOCK_UN);
  69.  
  70.           } else {
  71.             echo "FLOCK ERROR";
  72.           }
  73.  
  74.           fclose($newfile);
  75.           echo "Wpis dodany";
  76.           flock($info_file,LOCK_UN);
  77.         }
  78.       }
  79.   //  } else {
  80.   //    echo "ERROR FLOCK";
  81.   //  }
  82.  
  83.     fclose($info_file);
  84. }
  85.  
  86. if($found==false){
  87.   echo "Bledny uzytkownik/haslo";
  88. }
  89.  
  90. ?>
  91. <?php require 'foot.php';?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement