summaryrefslogtreecommitdiffstats
path: root/apps/files/ajax/rename.php
blob: 9fd2ce3ad4bc6d548aeb3a609e45863707ea7df7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php

// Init owncloud


OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();

// Get data
$dir = stripslashes($_GET["dir"]);
$file = stripslashes($_GET["file"]);
$newname = stripslashes($_GET["newname"]);

$l = OC_L10N::get('files');

if ( $newname !== '.' and ($dir != '' || $file != 'Shared') and $newname !== '.') {
	$targetFile = \OC\Files\Filesystem::normalizePath($dir . '/' . $newname);
	$sourceFile = \OC\Files\Filesystem::normalizePath($dir . '/' . $file);
	if(\OC\Files\Filesystem::rename($sourceFile, $targetFile)) {
		OCP\JSON::success(array("data" => array( "dir" => $dir, "file" => $file, "newname" => $newname )));
	} else {
		OCP\JSON::error(array("data" => array( "message" => $l->t("Unable to rename file") )));
	}
}else{
	OCP\JSON::error(array("data" => array( "message" => $l->t("Unable to rename file") )));
}