Advertisement
Guest User

Linas

a guest
Oct 20th, 2016
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.53 KB | None | 0 0
  1. useris@dev:~/web/public_html$ ls -al
  2. total 12
  3. drwxr-xr-x 2 useris useris 4096 Oct 20 15:12 .
  4. drwxr-x--x 5 useris useris 4096 Oct 20 11:17 ..
  5. -rw-r--r-- 1 useris useris 2167 Oct 20 15:12 info.php
  6.  
  7. code of: info.php
  8. <?php
  9. //phpinfo();
  10.  
  11. error_reporting(E_ALL);
  12. ini_set('display_errors',1);
  13.  
  14. function isFastCGI () {
  15.     return !is_null($_SERVER['FCGI_SERVER_VERSION']);
  16. }
  17.  
  18. var_dump(isFastCGI());
  19.  
  20. var_dump(getmyuid(), getmygid());
  21.  
  22. var_dump(is_writable('.'));
  23. var_dump(__DIR__);
  24.  
  25.  
  26. ?>
  27. <!DOCTYPE html>
  28. <html>
  29. <body>
  30.  
  31. <form action="" method="post" enctype="multipart/form-data">
  32.     Select image to upload:
  33.     <input type="file" name="fileToUpload" id="fileToUpload">
  34.     <input type="submit" value="Upload Image" name="submit">
  35. </form>
  36.  
  37. <?php
  38.  
  39.  
  40. if(isset($_FILES["fileToUpload"])){
  41.  
  42. $target_dir = "uploads/";
  43.  
  44. if(!file_exists(__DIR__.'/'.$target_dir)){
  45.  
  46.  
  47.  if(!mkdir(__DIR__.'/'.'uploads', 0755, true)) {
  48.         var_dump(error_get_last());
  49. }
  50.  
  51. }
  52. $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
  53. $uploadOk = 1;
  54. $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
  55. // Check if image file is a actual image or fake image
  56. if(isset($_POST["submit"])) {
  57.     $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
  58.     if($check !== false) {
  59.         echo "File is an image - " . $check["mime"] . ".";
  60.         $uploadOk = 1;
  61.     } else {
  62.         echo "File is not an image.";
  63.         $uploadOk = 0;
  64.     }
  65. }
  66. // Check if file already exists
  67. if (file_exists($target_file)) {
  68.     echo "Sorry, file already exists.";
  69.     $uploadOk = 0;
  70. }
  71. // Check file size
  72. if ($_FILES["fileToUpload"]["size"] > 500000) {
  73.     echo "Sorry, your file is too large.";
  74.     $uploadOk = 0;
  75. }
  76. // Allow certain file formats
  77. if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
  78. && $imageFileType != "gif" ) {
  79.     echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
  80.     $uploadOk = 0;
  81. }
  82. // Check if $uploadOk is set to 0 by an error
  83. if ($uploadOk == 0) {
  84.     echo "Sorry, your file was not uploaded.";
  85. // if everything is ok, try to upload file
  86. } else {
  87.     if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
  88.         echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
  89.     } else {
  90.         echo "Sorry, there was an error uploading your file.";
  91.         var_dump(error_get_last());
  92.     }
  93. }
  94.  
  95. }
  96. ?>
  97. </body>
  98. </html>
  99.  
  100. Response on upload
  101. Notice: Undefined index: FCGI_SERVER_VERSION in /home/useris/web/public_html/info.php on line 8
  102. bool(false) int(1000) int(1000) bool(false) string(28) "/home/useris/web/public_html"
  103. Select image to upload:  Choose File  Upload Image
  104.  
  105. Warning: mkdir(): Permission denied in /home/useris/web/public_html/info.php on line 40
  106. array(4) { ["type"]=> int(2) ["message"]=> string(26) "mkdir(): Permission denied" ["file"]=> string(37) "/home/useris/web/public_html/info.php" ["line"]=> int(40) } File is an image - image/jpeg.
  107. Warning: move_uploaded_file(uploads/Juslintek-Logo.jpg): failed to open stream: No such file or directory in /home/useris/web/public_html/info.php on line 80
  108.  
  109. Warning: move_uploaded_file(): Unable to move '/tmp/phpdpenOV' to 'uploads/Juslintek-Logo.jpg' in /home/useris/web/public_html/info.php on line 80
  110. Sorry, there was an error uploading your file.array(4) { ["type"]=> int(2) ["message"]=> string(85) "move_uploaded_file(): Unable to move '/tmp/phpdpenOV' to 'uploads/Juslintek-Logo.jpg'" ["file"]=> string(37) "/home/useris/web/public_html/info.php" ["line"]=> int(80) }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement