2011-10-23 09:40:40 +00:00
|
|
|
<?php
|
2015-02-26 10:37:37 +00:00
|
|
|
|
2011-10-23 09:40:40 +00:00
|
|
|
// Init owncloud
|
2012-07-22 01:56:51 +00:00
|
|
|
global $eventSource;
|
2012-04-17 17:31:29 +00:00
|
|
|
|
2015-01-20 11:24:13 +00:00
|
|
|
\OCP\JSON::checkLoggedIn();
|
|
|
|
\OCP\JSON::callCheck();
|
2011-10-23 09:40:40 +00:00
|
|
|
|
2014-07-16 17:40:22 +00:00
|
|
|
\OC::$server->getSession()->close();
|
2014-03-10 13:39:27 +00:00
|
|
|
|
2011-10-23 09:40:40 +00:00
|
|
|
// Get the params
|
2015-02-13 12:33:20 +00:00
|
|
|
$dir = isset( $_REQUEST['dir'] ) ? '/'.trim((string)$_REQUEST['dir'], '/\\') : '';
|
2015-02-18 16:44:13 +00:00
|
|
|
$fileName = isset( $_REQUEST['filename'] ) ? trim((string)$_REQUEST['filename'], '/\\') : '';
|
2014-09-11 17:21:56 +00:00
|
|
|
|
2014-08-31 08:05:59 +00:00
|
|
|
$l10n = \OC::$server->getL10N('files');
|
2013-10-22 16:11:03 +00:00
|
|
|
|
2013-10-23 08:49:43 +00:00
|
|
|
$result = array(
|
|
|
|
'success' => false,
|
|
|
|
'data' => NULL
|
2014-01-10 15:14:37 +00:00
|
|
|
);
|
2013-10-23 08:49:43 +00:00
|
|
|
|
2015-02-18 16:44:13 +00:00
|
|
|
try {
|
|
|
|
\OC\Files\Filesystem::getView()->verifyPath($dir, $fileName);
|
|
|
|
} catch (\OCP\Files\InvalidPathException $ex) {
|
|
|
|
$result['data'] = [
|
|
|
|
'message' => $ex->getMessage()];
|
2013-10-23 08:49:43 +00:00
|
|
|
OCP\JSON::error($result);
|
2015-02-18 16:44:13 +00:00
|
|
|
return;
|
2013-10-23 08:49:43 +00:00
|
|
|
}
|
|
|
|
|
2014-01-22 16:17:58 +00:00
|
|
|
if (!\OC\Files\Filesystem::file_exists($dir . '/')) {
|
|
|
|
$result['data'] = array('message' => (string)$l10n->t(
|
|
|
|
'The target folder has been moved or deleted.'),
|
|
|
|
'code' => 'targetnotfound'
|
|
|
|
);
|
|
|
|
OCP\JSON::error($result);
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:44:13 +00:00
|
|
|
$target = $dir.'/'.$fileName;
|
2013-10-23 08:49:43 +00:00
|
|
|
|
2013-10-22 16:11:03 +00:00
|
|
|
if (\OC\Files\Filesystem::file_exists($target)) {
|
2013-12-10 14:32:48 +00:00
|
|
|
$result['data'] = array('message' => (string)$l10n->t(
|
2013-10-23 15:02:41 +00:00
|
|
|
'The name %s is already used in the folder %s. Please choose a different name.',
|
2015-02-18 16:44:13 +00:00
|
|
|
array($fileName, $dir))
|
2013-10-23 09:01:05 +00:00
|
|
|
);
|
2013-10-22 16:11:03 +00:00
|
|
|
OCP\JSON::error($result);
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2015-03-02 20:06:25 +00:00
|
|
|
$success = false;
|
2015-03-02 20:33:17 +00:00
|
|
|
$templateManager = OC_Helper::getFileTemplateManager();
|
|
|
|
$mimeType = OC_Helper::getMimetypeDetector()->detectPath($target);
|
|
|
|
$content = $templateManager->getTemplate($mimeType);
|
2014-08-08 12:35:33 +00:00
|
|
|
|
2015-03-02 20:06:25 +00:00
|
|
|
if($content) {
|
|
|
|
$success = \OC\Files\Filesystem::file_put_contents($target, $content);
|
2012-08-28 22:50:12 +00:00
|
|
|
} else {
|
2015-03-02 20:06:25 +00:00
|
|
|
$success = \OC\Files\Filesystem::touch($target);
|
|
|
|
}
|
2013-08-08 19:27:59 +00:00
|
|
|
|
2015-03-02 20:06:25 +00:00
|
|
|
if($success) {
|
|
|
|
$meta = \OC\Files\Filesystem::getFileInfo($target);
|
|
|
|
OCP\JSON::success(array('data' => \OCA\Files\Helper::formatFileInfo($meta)));
|
2015-03-02 20:33:17 +00:00
|
|
|
return;
|
2011-10-23 09:40:40 +00:00
|
|
|
}
|
|
|
|
|
2013-10-23 15:02:41 +00:00
|
|
|
OCP\JSON::error(array('data' => array( 'message' => $l10n->t('Error when creating the file') )));
|