Advertisement
shriek

Gmail Attach

Feb 12th, 2012
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2. <?php
  3. /* ignore Class Upload... */
  4. class Upload
  5. {
  6.     public function __construct()
  7.     {
  8.         $width = 200;
  9.         $height = 200;
  10.     }
  11.     /*public function __construct($customWidth, $customHeight)
  12.     {
  13.         $width = $customwidth;
  14.         $height = $customHeight;
  15.     }
  16.      */
  17.     public function makeDir($dir)
  18.     {
  19.         if(mkdir($dir))
  20.             return true;
  21.     }
  22.     public function setDirs()
  23.     {
  24.         if(!is_dir("uploads")) 
  25.         {
  26.             if(Upload::makeDir("uploads")&&Upload::makeDir("uploads/username"))
  27.                 return true;
  28.             else
  29.                 return false;
  30.         }
  31.         else if(!is_dir("uploads/username"))
  32.         {
  33.             if(Upload::makeDir("uploads/username"))
  34.                 return true;
  35.             else
  36.                 return false;
  37.         }
  38.         return true;
  39.     }
  40.     public function checkFiles($files)
  41.     {
  42.         $counter = 0;
  43.         print_r(get_headers('http://localhost/Uploadr/uploader.php'));
  44.         while($counter<count($files))
  45.         {
  46.             if(file_exists("uploads/username/".$files[$counter]))
  47.                 echo "<br/>".$files[$counter]. " already exists<br/>";
  48.             $counter++;
  49.         }
  50.  
  51.     }
  52.     public function pushUpload()
  53.     {  
  54.         if(isset($_POST['submit']))
  55.         {
  56.             echo "<pre>";
  57.             print_r($_FILES);
  58.             echo "</pre>";
  59.             if(Upload::setDirs())
  60.             {
  61.                 Upload::checkFiles($_FILES["docs"]["name"]);
  62.                 /*
  63.                 foreach($_FILES["docs"]["error"] as $key =>$error)
  64.                 {
  65.                     if($error == UPLOAD_ERR_OK)
  66.                     {
  67.                         $name = $_FILES["docs"]["name"][$key];
  68.                         move_uploaded_file($_FILES["docs"]["tmp_name"][$key], "uploads/username/".$_FILES["docs"]["name"][$key]);
  69.                     }
  70.                 }*/
  71.             }
  72.             else
  73.             {
  74.                 echo "Cannot make necessary directories";
  75.                 return false;
  76.             }
  77.         }
  78.         return true;
  79.     }
  80.     public function getValidation()
  81.     {
  82.     }
  83. }
  84. if(isset($_POST['submit']))
  85.     if(Upload::pushUpload())
  86.         echo "Success";
  87. ?>
  88. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  89. <script type="text/javascript">
  90. $(document).ready(function(){
  91. var attacher= new Array();
  92. var fileCounter = 0;
  93.     $('#attacher').click(function(){
  94.         var li = document.createElement('li');
  95.         li.setAttribute('id','file'+fileCounter);
  96.         li.innerHTML = '<input type="file" name="docs[]" id="docs'+fileCounter+'"/>';
  97.         document.getElementById('parentFilelist').appendChild(li);
  98.         $('#docs'+fileCounter).click();
  99.         fileCounter++;
  100.     });
  101. });
  102. </script>
  103. <body>
  104. <div id="shout">
  105.     <form method='POST' enctype='multipart/form-data' action="<?php $_SERVER['PHP_SELF'];?>">
  106.         <input type='hidden' name='MAX_FILE_SIZE' value='2000000'/>
  107.         <ul id='parentFilelist'></ul>
  108.         <a href='#' id='attacher'>Attach Files</a>
  109.         <input type='submit' name='submit' id='btn' value='Upload'/>
  110.     </form>
  111. </div>
  112. <div id="formBox">
  113. </div>
  114. </body>
  115. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement