Advertisement
droidus

Untitled

Aug 29th, 2011
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.42 KB | None | 0 0
  1.   <?php
  2.   // DELETE THE USER-SPECIFIED FILES
  3. if(isset($_POST['submit'])) {
  4.     $deletedFile = $_POST['file'];
  5.     if(empty($deletedFile)) {
  6.         echo("<div class='error'>You didn't choose to delete any files.</div>");
  7.     }
  8.     else {     
  9.         $query = "SELECT `bandwhitch`, `freeSpace`
  10.          FROM members
  11.          WHERE uname='$_SESSION[user]'";
  12. $result = mysql_query($query) or die(mysql_error());
  13.                         if (mysql_num_rows($result) > 0) {
  14.                             $row = mysql_fetch_array($result) or die(mysql_error());
  15.                            
  16.             $deletedFiles = $row['bandwhitch'] - $totalSizeDeletedFiles; // Gets the new bandwhitch total
  17.             mysql_query("UPDATE members SET bandwhitch = '$deletedFiles' WHERE uname='$_SESSION[user]'");
  18.            
  19.             $freeSpace = $row['freeSpace'] + $totalSizeDeletedFiles; // Update the free space left on their account
  20.             mysql_query("UPDATE members SET freeSpace = '$freeSpace' WHERE uname='$_SESSION[user]'");
  21.            
  22.             mysql_close($uploader);
  23.                         }
  24.                
  25.         for ($i=0; $i<$count; $i++) {
  26.             if ($i == $count-1) { // if this is the last file that they are deleting... use "and"
  27.                 unlink("users/" . $_SESSION['user'] . "/uploads/" . $deletedFile[$i]);
  28.                 echo (" and <b>" . $deletedFile[$i] . "</b>.");
  29.             }
  30.             else {
  31.                 echo ("<b>" . $deletedFile[$i] . ", </b> ");
  32.                 unlink("users/" . $_SESSION['user'] . "/uploads/" . $deletedFile[$i]);
  33.             }
  34.         }
  35.     }
  36. }
  37.  
  38.   // THIS SCRIPT SHOWS THE UPLOADED FILES
  39. if ($handle = opendir('users/' . $_SESSION['user'] . '/uploads/')) {
  40.     print ("<form action='' method='post' id='deleteFiles' name='deleteFiles'> <table border=1 cellpadding='1' cellspacing='1' width='75%'>
  41. <TR><TH>File Name</TH><th>File Size</th><th>Delete</th><th>Date Last Modified</th><th>Download</th></TR>");
  42.     while (false !== ($file = readdir($handle))) {
  43.         if ($file != "." && $file != ".." && (!(is_dir($file)))) {
  44.             print("<TR><Td>");
  45.             if ((pathinfo($file, PATHINFO_EXTENSION)) == "mp4")
  46.             {          
  47.                 $_SESSION['videoFile'] = $_SESSION['user']."/uploads/".$file;
  48.                 echo "<a href='video/play.php' target='_blank'>$file</a>\n\n";
  49.             }
  50.             else if ((pathinfo($file, PATHINFO_EXTENSION)) == "txt" || (pathinfo($file, PATHINFO_EXTENSION)) == "doc" || (pathinfo($file, PATHINFO_EXTENSION)) == "docx")
  51.             {          
  52.                 $_SESSION['editDocumentText'] = $_SERVER['DOCUMENT_ROOT'] . "users/" . $_SESSION['user']."/uploads/".$file;
  53.                 echo "<a href='wysiwyg/text_editor.php' target='_blank'>$file</a>\n\n";
  54.             }
  55.             else if ((pathinfo($file, PATHINFO_EXTENSION)) == "mp3")
  56.             {          
  57.                 echo "<a href='music_player/iPlay.php?file=$file' target='_blank'>$file</a>\n\n";
  58.             }
  59.             else
  60.             {
  61.                 echo "<a href='users/$_SESSION[user]/uploads/$file' target='_blank'>$file</a>\n";
  62.             }
  63.             print("</td><td>");
  64.             $fileSize = round(((filesize($file)) / 1000),8); // Gets you MB
  65.             echo $fileSize." MB <br>";
  66.             $usedStorage = $fileSize + $usedStroage;
  67.             print("</td>");
  68.             print ("<td align='center'><input name='file' type='checkbox' value='$file' /></td>");
  69.             print ("<td>" . date ('F d Y H:i:s.', filemtime($file)) . "</td>");
  70.             print "<td><a href='download.php?f=". $file . "' target='_blank'><img src='http://www.mysite.com/Images/icn_file_download.png' width='50' height='50' title='Download this file!' style='margin-left:auto; margin-right:auto;' /></a></td>";
  71.         }
  72.     }
  73.     print("</tr></table>");
  74.     closedir($handle);
  75. }
  76. echo("<br><input type='submit' name='submit' id='submit' value='Delete Checked Files' />");
  77. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement