Advertisement
salehnaveed

Website Rename PHP

Apr 22nd, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.91 KB | None | 0 0
  1. <?php
  2.  
  3. session_start();
  4. if( $_SESSION["username"]==""){
  5.  header("Location: http://filewallet.site88.net/");
  6. }
  7. else{
  8.        $servername = "mysql1.000webhost.com";
  9.        $username = "a9691255_naveed";
  10.        $password = "abmirzass123";
  11.        $dbname = "a9691255_webiste";
  12. $userid=$_SESSION["username"];
  13.  
  14. // Create connection
  15. $conn = new mysqli($servername, $username, $password, $dbname);
  16. // Check connection
  17. if ($conn->connect_error) {
  18.     die("Connection failed: " . $conn->connect_error);
  19. }
  20. if(isset($_GET["choice"])){
  21.          $choice=$_GET["choice"];
  22. if($choice==1)
  23. {
  24.       $path=$_GET["path"];
  25.       $filename=$_GET["filename"];
  26. }
  27. if($choice==2)
  28. {
  29.      
  30.       $filename=$_GET["filename"];
  31. echo $filename;
  32. }
  33. }
  34.  
  35. }
  36.  
  37. ?> 
  38. <html>
  39. <body>
  40. <?php
  41. if(isset($_POST["submit"])){
  42.          $oldname=$_POST["oldname"];
  43.          $newname=$_POST["newname"];
  44.          $filepath="upload/".$userid;
  45. if (strpos($oldname, '.') !== false) {
  46.     $filecheck=1;
  47. }
  48. else{$filecheck=2;}
  49. if($filecheck==1){
  50.       $query="update fileuploads set filename='".$newname."' ,filepath='".$filepath."/".$newname."' where filename='".$oldname."' and userid='".$userid."'";
  51.                 if($conn->query($query))
  52.                         {
  53.                             if(rename($filepath."/".$oldname,$filepath."/".$newname))
  54.                             header("Location: main.php?renamecheck=1");
  55.                                                         else
  56.                                                          header("Location: main.php?renamecheck=2");
  57. }
  58.     }
  59. if($filecheck==2){
  60. if(rename($filepath."/".$oldname,$filepath."/".$newname))
  61.                             header("Location: main.php?renamecheck=1");
  62. }
  63.                    
  64. }
  65.  
  66. ?>
  67. <form method="post" action="rename.php">
  68. Old File Name : <input type="text" name="oldname" width="100px" value="<?php echo $filename; ?>" readonly><br>
  69. New File name : <input type="text" name="newname" width="100px"><br>
  70. <input type="submit" name="submit">
  71. </form>
  72. </body>
  73. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement