Advertisement
ZaraByte

ZaraByte File Uploader

Nov 27th, 2012
6,302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>ZaraByte File Uploader</title>
  6. <link href="style/style.css" rel="stylesheet" type="text/css" />
  7. </head>
  8.  
  9. <body>
  10. <?php
  11. $myUpload = new maxUpload();
  12. //$myUpload->setUploadLocation(getcwd().DIRECTORY_SEPARATOR);
  13. $myUpload->uploadFile();
  14. ?>
  15. <?php
  16. /*************************************************
  17. * ZaraByte File Uploader
  18. *
  19. * Version: 1.0
  20. * Date: 2009-09-29
  21. *
  22. ****************************************************/
  23. class maxUpload{
  24. var $uploadLocation;
  25.  
  26. /**
  27. * Constructor to initialize class varaibles
  28. * The uploadLocation will be set to the actual
  29. * working directory
  30. *
  31. * @return maxUpload
  32. */
  33. function maxUpload(){
  34. $this->uploadLocation = getcwd().DIRECTORY_SEPARATOR;
  35. }
  36.  
  37. /**
  38. * This function sets the directory where to upload the file
  39. * In case of Windows server use the form: c:\\temp\\
  40. * In case of Unix server use the form: /tmp/
  41. *
  42. * @param String Directory where to store the files
  43. */
  44. function setUploadLocation($dir){
  45. $this->uploadLocation = $dir;
  46. }
  47.  
  48. function showUploadForm($msg='',$error=''){
  49. ?>
  50. <div id="container">
  51. <div id="header"><div id="header_left"></div>
  52. <div id="header_main">ZaraByte's File Uploader</div><div id="header_right"></div></div>
  53. <div id="content">
  54. <?php
  55. if ($msg != ''){
  56. echo '<p class="msg">'.$msg.'</p>';
  57. } else if ($error != ''){
  58. echo '<p class="emsg">'.$error.'</p>';
  59.  
  60. }
  61. ?>
  62. <form action="" method="post" enctype="multipart/form-data" >
  63. <center>
  64. <label>File:
  65. <input name="myfile" type="file" size="30" />
  66. </label>
  67. <label>
  68. <input type="submit" name="submitBtn" class="sbtn" value="Upload" />
  69. </label>
  70. </center>
  71. </form>
  72. </div>
  73. <div id="footer"><a href="http://www.zarabyte.com" target="_blank">ZaraByte File Uploader</a></div>
  74. </div>
  75. <?php
  76. }
  77.  
  78. function uploadFile(){
  79. if (!isset($_POST['submitBtn'])){
  80. $this->showUploadForm();
  81. } else {
  82. $msg = '';
  83. $error = '';
  84.  
  85. //Check destination directory
  86. if (!file_exists($this->uploadLocation)){
  87. $error = "The target directory doesn't exists!";
  88. } else if (!is_writeable($this->uploadLocation)) {
  89. $error = "The target directory is not writeable!";
  90. } else {
  91. $target_path = $this->uploadLocation . basename( $_FILES['myfile']['name']);
  92.  
  93. if(@move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) {
  94. $msg = basename( $_FILES['myfile']['name']).
  95. " was uploaded successfully!";
  96. } else{
  97. $error = "The upload process failed!";
  98. }
  99. }
  100.  
  101. $this->showUploadForm($msg,$error);
  102. }
  103.  
  104. }
  105.  
  106. }
  107. ?>
  108. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement