Advertisement
melody45

Untitled

Dec 18th, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. ?php
  2. session_start();
  3. require_once("include/connection.php");
  4. ?>
  5. <form action="" method="post">
  6. <label for="new_file_name">Newname: </label>
  7. <input type="taxt" name="new_file_name" value="" />
  8. <br/><br/>
  9. <input type="submit" name="file_rename_submit" value="Rename"/>
  10. </form>
  11.  
  12. <?php
  13. if(isset($_POST['new_file_name']))
  14. {
  15. $currentFolder = $_SESSION['currentDirectory'];
  16. $new_file_name = $_POST['new_file_name'];
  17. $ori_name=$_GET['name'];
  18. $t = 0;
  19. $l = strlen($ori_name);
  20. for($s=0; $s<$l; $s++){
  21. if($ori_name[$s] == '/')$t=1;
  22. }
  23. for($s=0; $s<$l; $s++)
  24. if($ori_name[$s] == '.'){
  25. $c = "";
  26. $len = strlen($ori_name);
  27. for($j=0; $j<$len; $j++){
  28. if($ori_name[$j] == '.')
  29. for($k=$j; $k<$len; $k++) $c .= $ori_name[$k];
  30. }
  31. $new_path = $new_path.$c;
  32. $new_file_name .= $c;
  33. }
  34.  
  35. $query = "SELECT * FROM infotable";
  36. $result = mysql_query($query);
  37. $flag = 0;
  38. while($row=mysql_fetch_array($result))
  39. {
  40.  
  41. if(!strcmp($new_path, $row['file_location']) && $row['file_name'] == $new_file_name)
  42. {
  43. $flag = 1;
  44. echo "File exits. Please use another name";
  45. header('Refresh: 3;URL=rename.php');
  46. }
  47. }
  48.  
  49. if($flag == 0)
  50. {
  51. $chk = "dir";
  52. $del = mysql_query("SELECT *FROM infotable WHERE file_name = '$ori_name'");
  53. while($dirfi = mysql_fetch_array($del)){
  54. if($dirfi['file_type'] == $chk){
  55. //echo $new_path."---".$path;
  56. mkdir($new_path);
  57. rmdir($path);
  58. }else {
  59.  
  60. $data = file_get_contents($path);
  61. $file = fopen($new_path,'w+');
  62. fputs($file,$data);
  63. fclose($file);
  64. unlink($path);
  65. }
  66. }
  67. $query1 = "UPDATE infotable SET file_name='$new_file_name',file_location='$new_path' WHERE file_name='$ori_name'";
  68. if(mysql_query($query1))
  69. {
  70.  
  71. echo "Rename Successful.Please wait...";
  72. header('Refresh: 2;URL=main.php');
  73. }
  74. }
  75. }
  76. ?>
  77.  
  78. <?php
  79. mysql_close();
  80. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement