Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ?php
- session_start();
- require_once("include/connection.php");
- ?>
- <form action="" method="post">
- <label for="new_file_name">Newname: </label>
- <input type="taxt" name="new_file_name" value="" />
- <br/><br/>
- <input type="submit" name="file_rename_submit" value="Rename"/>
- </form>
- <?php
- if(isset($_POST['new_file_name']))
- {
- $currentFolder = $_SESSION['currentDirectory'];
- $new_file_name = $_POST['new_file_name'];
- $ori_name=$_GET['name'];
- $t = 0;
- $l = strlen($ori_name);
- for($s=0; $s<$l; $s++){
- if($ori_name[$s] == '/')$t=1;
- }
- for($s=0; $s<$l; $s++)
- if($ori_name[$s] == '.'){
- $c = "";
- $len = strlen($ori_name);
- for($j=0; $j<$len; $j++){
- if($ori_name[$j] == '.')
- for($k=$j; $k<$len; $k++) $c .= $ori_name[$k];
- }
- $new_path = $new_path.$c;
- $new_file_name .= $c;
- }
- $query = "SELECT * FROM infotable";
- $result = mysql_query($query);
- $flag = 0;
- while($row=mysql_fetch_array($result))
- {
- if(!strcmp($new_path, $row['file_location']) && $row['file_name'] == $new_file_name)
- {
- $flag = 1;
- echo "File exits. Please use another name";
- header('Refresh: 3;URL=rename.php');
- }
- }
- if($flag == 0)
- {
- $chk = "dir";
- $del = mysql_query("SELECT *FROM infotable WHERE file_name = '$ori_name'");
- while($dirfi = mysql_fetch_array($del)){
- if($dirfi['file_type'] == $chk){
- //echo $new_path."---".$path;
- mkdir($new_path);
- rmdir($path);
- }else {
- $data = file_get_contents($path);
- $file = fopen($new_path,'w+');
- fputs($file,$data);
- fclose($file);
- unlink($path);
- }
- }
- $query1 = "UPDATE infotable SET file_name='$new_file_name',file_location='$new_path' WHERE file_name='$ori_name'";
- if(mysql_query($query1))
- {
- echo "Rename Successful.Please wait...";
- header('Refresh: 2;URL=main.php');
- }
- }
- }
- ?>
- <?php
- mysql_close();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement