Blame view
sources/apps/files/ajax/newfolder.php
1.74 KB
|
03e52840d
|
1 2 3 4 5 6 7 |
<?php // Init owncloud OCP\JSON::checkLoggedIn(); OCP\JSON::callCheck(); |
|
6d9380f96
|
8 |
\OC::$session->close(); |
|
03e52840d
|
9 10 11 12 |
// Get the params $dir = isset( $_POST['dir'] ) ? stripslashes($_POST['dir']) : ''; $foldername = isset( $_POST['foldername'] ) ? stripslashes($_POST['foldername']) : ''; |
|
31b7f2792
|
13 14 15 16 17 18 19 20 21 22 23 24 |
$l10n = \OC_L10n::get('files');
$result = array(
'success' => false,
'data' => NULL
);
if(trim($foldername) === '') {
$result['data'] = array('message' => $l10n->t('Folder name cannot be empty.'));
OCP\JSON::error($result);
exit();
}
|
|
6d9380f96
|
25 26 27 28 29 30 31 32 33 34 35 |
if(!OCP\Util::isValidFileName($foldername)) {
$result['data'] = array('message' => (string)$l10n->t("Invalid name, '\\', '/', '<', '>', ':', '\"', '|', '?' and '*' are not allowed."));
OCP\JSON::error($result);
exit();
}
if (!\OC\Files\Filesystem::file_exists($dir . '/')) {
$result['data'] = array('message' => (string)$l10n->t(
'The target folder has been moved or deleted.'),
'code' => 'targetnotfound'
);
|
|
31b7f2792
|
36 |
OCP\JSON::error($result); |
|
03e52840d
|
37 38 |
exit(); } |
|
31b7f2792
|
39 40 41 42 43 44 45 46 47 48 |
//TODO why is stripslashes used on foldername here but not in newfile.php?
$target = $dir . '/' . stripslashes($foldername);
if (\OC\Files\Filesystem::file_exists($target)) {
$result['data'] = array('message' => $l10n->t(
'The name %s is already used in the folder %s. Please choose a different name.',
array($foldername, $dir))
);
OCP\JSON::error($result);
|
|
03e52840d
|
49 50 |
exit(); } |
|
31b7f2792
|
51 52 |
if(\OC\Files\Filesystem::mkdir($target)) {
if ( $dir !== '/') {
|
|
03e52840d
|
53 54 55 56 57 |
$path = $dir.'/'.$foldername;
} else {
$path = '/'.$foldername;
}
$meta = \OC\Files\Filesystem::getFileInfo($path);
|
|
6d9380f96
|
58 59 |
$meta['type'] = 'dir'; // missing ?!
OCP\JSON::success(array('data' => \OCA\Files\Helper::formatFileInfo($meta)));
|
|
03e52840d
|
60 61 |
exit(); } |
|
31b7f2792
|
62 |
OCP\JSON::error(array('data' => array( 'message' => $l10n->t('Error when creating the folder') )));
|