本文整理汇总了PHP中OC\Files\Filesystem::mkdir方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::mkdir方法的具体用法?PHP Filesystem::mkdir怎么用?PHP Filesystem::mkdir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC\Files\Filesystem
的用法示例。
在下文中一共展示了Filesystem::mkdir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Add
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function Add()
{
\OCP\JSON::setContentTypeHeader('application/json');
if (isset($_POST['FILE']) && strlen($_POST['FILE']) > 0 && Tools::CheckURL($_POST['FILE']) && isset($_POST['OPTIONS'])) {
try {
$Target = Tools::CleanString(substr($_POST['FILE'], strrpos($_POST['FILE'], '/') + 1));
// If target file exists, create a new one
if (\OC\Files\Filesystem::file_exists($this->DownloadsFolder . '/' . $Target)) {
$Target = time() . '_' . $Target;
}
// Create the target file if the downloader is Aria2
if ($this->WhichDownloader == 0) {
\OC\Files\Filesystem::touch($this->DownloadsFolder . '/' . $Target);
} else {
if (!\OC\Files\Filesystem::is_dir($this->DownloadsFolder)) {
\OC\Files\Filesystem::mkdir($this->DownloadsFolder);
}
}
// Build OPTIONS array
$OPTIONS = array('dir' => $this->AbsoluteDownloadsFolder, 'out' => $Target, 'follow-torrent' => false);
if (isset($_POST['OPTIONS']['FTPUser']) && strlen(trim($_POST['OPTIONS']['FTPUser'])) > 0 && isset($_POST['OPTIONS']['FTPPasswd']) && strlen(trim($_POST['OPTIONS']['FTPPasswd'])) > 0) {
$OPTIONS['ftp-user'] = $_POST['OPTIONS']['FTPUser'];
$OPTIONS['ftp-passwd'] = $_POST['OPTIONS']['FTPPasswd'];
}
if (isset($_POST['OPTIONS']['FTPPasv']) && strlen(trim($_POST['OPTIONS']['FTPPasv'])) > 0) {
$OPTIONS['ftp-pasv'] = strcmp($_POST['OPTIONS']['FTPPasv'], "true") == 0 ? true : false;
}
if (!$this->ProxyOnlyWithYTDL && !is_null($this->ProxyAddress) && $this->ProxyPort > 0 && $this->ProxyPort <= 65536) {
$OPTIONS['all-proxy'] = rtrim($this->ProxyAddress, '/') . ':' . $this->ProxyPort;
if (!is_null($this->ProxyUser) && !is_null($this->ProxyPasswd)) {
$OPTIONS['all-proxy-user'] = $this->ProxyUser;
$OPTIONS['all-proxy-passwd'] = $this->ProxyPasswd;
}
}
$AddURI = $this->WhichDownloader == 0 ? Aria2::AddUri(array($_POST['FILE']), array('Params' => $OPTIONS)) : CURL::AddUri($_POST['FILE'], $OPTIONS);
if (isset($AddURI['result']) && !is_null($AddURI['result'])) {
$SQL = 'INSERT INTO `*PREFIX*ocdownloader_queue` (`UID`, `GID`, `FILENAME`, `PROTOCOL`, `STATUS`, `TIMESTAMP`) VALUES (?, ?, ?, ?, ?, ?)';
if ($this->DbType == 1) {
$SQL = 'INSERT INTO *PREFIX*ocdownloader_queue ("UID", "GID", "FILENAME", "PROTOCOL", "STATUS", "TIMESTAMP") VALUES (?, ?, ?, ?, ?, ?)';
}
$Query = \OCP\DB::prepare($SQL);
$Result = $Query->execute(array($this->CurrentUID, $AddURI['result'], $Target, strtoupper(substr($_POST['FILE'], 0, strpos($_POST['FILE'], ':'))), 1, time()));
sleep(1);
$Status = $this->WhichDownloader == 0 ? Aria2::TellStatus($AddURI['result']) : CURL::TellStatus($AddURI['result']);
$Progress = 0;
if ($Status['result']['totalLength'] > 0) {
$Progress = $Status['result']['completedLength'] / $Status['result']['totalLength'];
}
$ProgressString = Tools::GetProgressString($Status['result']['completedLength'], $Status['result']['totalLength'], $Progress);
return new JSONResponse(array('ERROR' => false, 'MESSAGE' => (string) $this->L10N->t('Download started'), 'GID' => $AddURI['result'], 'PROGRESSVAL' => round($Progress * 100, 2) . '%', 'PROGRESS' => is_null($ProgressString) ? (string) $this->L10N->t('N/A') : $ProgressString, 'STATUS' => isset($Status['result']['status']) ? (string) $this->L10N->t(ucfirst($Status['result']['status'])) : (string) $this->L10N->t('N/A'), 'STATUSID' => Tools::GetDownloadStatusID($Status['result']['status']), 'SPEED' => isset($Status['result']['downloadSpeed']) ? Tools::FormatSizeUnits($Status['result']['downloadSpeed']) . '/s' : (string) $this->L10N->t('N/A'), 'FILENAME' => strlen($Target) > 40 ? substr($Target, 0, 40) . '...' : $Target, 'PROTO' => strtoupper(substr($_POST['FILE'], 0, strpos($_POST['FILE'], ':'))), 'ISTORRENT' => false));
} else {
return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t($this->WhichDownloader == 0 ? 'Returned GID is null ! Is Aria2c running as a daemon ?' : 'An error occurred while running the CURL download')));
}
} catch (Exception $E) {
return new JSONResponse(array('ERROR' => true, 'MESSAGE' => $E->getMessage()));
}
} else {
return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('Please check the URL you\'ve just provided')));
}
}
示例2: savePersonal
/**
* @NoAdminRequired
*/
public function savePersonal($savePath)
{
if (is_null($savePath)) {
$savePath = '/';
}
$status = true;
if (\OC\Files\Filesystem::file_exists($savePath) === false) {
$status = \OC\Files\Filesystem::mkdir($savePath);
}
if ($status) {
$this->appConfig->setUserValue($this->userId, 'save_path', $savePath);
$response = array('status' => 'success', 'data' => array('message' => $this->l10n->t('Directory saved successfully.')));
} else {
$response = array('status' => 'error', 'data' => array('message' => $this->l10n->t('An error occurred while changing directory.')));
}
return $response;
}
示例3: setUp
public function setUp()
{
parent::setUp();
$this->userBackend = new \Test\Util\User\Dummy();
\OC::$server->getUserManager()->registerBackend($this->userBackend);
$this->ownerUid = $this->getUniqueID('owner_');
$this->recipientUid = $this->getUniqueID('recipient_');
$this->userBackend->createUser($this->ownerUid, '');
$this->userBackend->createUser($this->recipientUid, '');
$this->loginAsUser($this->ownerUid);
Filesystem::mkdir('/foo');
Filesystem::file_put_contents('/foo/bar.txt', 'asd');
$fileId = Filesystem::getFileInfo('/foo/bar.txt')->getId();
\OCP\Share::shareItem('file', $fileId, \OCP\Share::SHARE_TYPE_USER, $this->recipientUid, 31);
$this->loginAsUser($this->recipientUid);
$this->assertTrue(Filesystem::file_exists('bar.txt'));
}
示例4: __construct
public function __construct($AppName, IRequest $request, $UserId)
{
parent::__construct($AppName, $request);
$this->userId = $UserId;
$path = self::PROJECTKIT_PREFIX . DIRECTORY_SEPARATOR;
if (isset($_GET['containerId'])) {
$path .= self::PROJECT_PREFIX . (string) $_GET['containerId'] . DIRECTORY_SEPARATOR;
if (isset($_GET['targetType']) && isset($_GET['targetId'])) {
switch ($_GET['targetType']) {
case TargetType::TASK:
$path .= self::TASK_PREFIX;
break;
case TargetType::ISSUE:
$path .= self::ISSUE_PREFIX;
break;
default:
break;
}
$path .= (string) $_GET['targetId'] . DIRECTORY_SEPARATOR;
$_SESSION['targetType'] = $_GET['targetType'];
} elseif (!isset($_GET['targetType']) && !isset($_GET['targetId'])) {
$_SESSION['targetType'] = TargetType::PROJECT;
}
//use session to save targetType
$path = Filesystem::normalizePath($path);
//Create folder for path
if (!Filesystem::file_exists($path)) {
try {
Filesystem::mkdir($path);
} catch (\Exception $e) {
$result = ['success' => false, 'data' => ['message' => $e->getMessage()]];
\OCP\JSON::error($result);
exit;
}
}
if (!isset($_GET['dir'])) {
$params = array_merge($_GET, ["dir" => $path]);
$url = $_SERVER['PHP_SELF'] . '?' . http_build_query($params);
header('Location: ' . $url, true, 302);
exit;
}
}
}
示例5: testNewUser
public function testNewUser()
{
$user1 = $this->getUniqueID('user_');
$this->userBackend->createUser($user1, '');
$this->loginAsUser($user1);
Filesystem::mkdir('/folder');
Filesystem::mkdir('/folder/subfolder');
Filesystem::file_put_contents('/foo.txt', 'asd');
Filesystem::file_put_contents('/folder/bar.txt', 'fgh');
Filesystem::file_put_contents('/folder/subfolder/qwerty.txt', 'jkl');
$files = array('/foo.txt', '/folder/bar.txt', '/folder/subfolder', '/folder/subfolder/qwerty.txt');
$originalEtags = $this->getEtags($files);
$scanner = new \OC\Files\Utils\Scanner($user1, \OC::$server->getDatabaseConnection(), \OC::$server->getLogger());
$scanner->backgroundScan('/');
$newEtags = $this->getEtags($files);
// loop over array and use assertSame over assertEquals to prevent false positives
foreach ($originalEtags as $file => $originalEtag) {
$this->assertSame($originalEtag, $newEtags[$file]);
}
}
示例6: testUnshareChildren
/**
* @medium
*/
function testUnshareChildren()
{
$fileInfo2 = \OC\Files\Filesystem::getFileInfo($this->folder);
$this->share(\OCP\Share::SHARE_TYPE_USER, $this->folder, self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_ALL);
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
// one folder should be shared with the user
$shares = $this->shareManager->getSharedWith(self::TEST_FILES_SHARING_API_USER2, \OCP\Share::SHARE_TYPE_USER);
$this->assertCount(1, $shares);
// move shared folder to 'localDir'
\OC\Files\Filesystem::mkdir('localDir');
$result = \OC\Files\Filesystem::rename($this->folder, '/localDir/' . $this->folder);
$this->assertTrue($result);
\OC\Files\Filesystem::unlink('localDir');
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
// after the parent directory was deleted the share should be unshared
$shares = $this->shareManager->getSharedWith(self::TEST_FILES_SHARING_API_USER2, \OCP\Share::SHARE_TYPE_USER);
$this->assertEmpty($shares);
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
// the folder for the owner should still exists
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->folder));
}
示例7: testNewUser
public function testNewUser()
{
$user1 = uniqid('user_');
$this->userBackend->createUser($user1, '');
\OC_Util::tearDownFS();
\OC_User::setUserId($user1);
\OC_Util::setupFS($user1);
Filesystem::mkdir('/folder');
Filesystem::mkdir('/folder/subfolder');
Filesystem::file_put_contents('/foo.txt', 'asd');
Filesystem::file_put_contents('/folder/bar.txt', 'fgh');
Filesystem::file_put_contents('/folder/subfolder/qwerty.txt', 'jkl');
$files = array('/foo.txt', '/folder/bar.txt', '/folder/subfolder', '/folder/subfolder/qwerty.txt');
$originalEtags = $this->getEtags($files);
$scanner = new \OC\Files\Utils\Scanner($user1);
$scanner->backgroundScan('/');
$newEtags = $this->getEtags($files);
// loop over array and use assertSame over assertEquals to prevent false positives
foreach ($originalEtags as $file => $originalEtag) {
$this->assertSame($originalEtag, $newEtags[$file]);
}
}
示例8: testpreUnlink
/**
* @medium
*/
function testpreUnlink()
{
$fileInfo2 = \OC\Files\Filesystem::getFileInfo($this->folder);
$result = \OCP\Share::shareItem('folder', $fileInfo2->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
$this->assertTrue($result);
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
// one folder should be shared with the user
$sharedFolders = \OCP\Share::getItemsSharedWith('folder');
$this->assertSame(1, count($sharedFolders));
// move shared folder to 'localDir'
\OC\Files\Filesystem::mkdir('localDir');
$result = \OC\Files\Filesystem::rename($this->folder, '/localDir/' . $this->folder);
$this->assertTrue($result);
\OC\Files\Filesystem::unlink('localDir');
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
// after the parent directory was deleted the share should be unshared
$sharedFolders = \OCP\Share::getItemsSharedWith('folder');
$this->assertTrue(empty($sharedFolders));
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
// the folder for the owner should still exists
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->folder));
}
示例9: Save
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function Save()
{
\OCP\JSON::setContentTypeHeader('application/json');
$Error = false;
$Message = '';
if (isset($_POST['KEY']) && strlen(trim($_POST['KEY'])) > 0 && isset($_POST['VAL']) && strlen(trim($_POST['VAL'])) > 0) {
$PostKey = str_replace('OCD', '', $_POST['KEY']);
$PostValue = ltrim(trim(str_replace(' ', '\\ ', $_POST['VAL'])), '/');
if (in_array($PostKey, $this->OCDSettingKeys)) {
$this->Settings->SetKey($PostKey);
// Pre-Save process
if (strcmp($PostKey, 'DownloadsFolder') == 0 || strcmp($PostKey, 'TorrentsFolder') == 0) {
// check folder exists, if not create it
if (!\OC\Files\Filesystem::is_dir($PostValue)) {
// Create the target file
\OC\Files\Filesystem::mkdir($PostValue);
$Message .= $this->L10N->t('The folder doesn\'t exist. It has been created.');
}
}
if (strlen(trim($PostValue)) <= 0) {
$PostValue = null;
}
if ($this->Settings->CheckIfKeyExists()) {
$this->Settings->UpdateValue($PostValue);
} else {
$this->Settings->InsertValue($PostValue);
}
} else {
$Error = true;
$Message = $this->L10N->t('Unknown field');
}
} else {
$Error = true;
$Message = $this->L10N->t('Undefined field');
}
return new JSONResponse(array('ERROR' => $Error, 'MESSAGE' => strlen(trim($Message)) == 0 ? (string) $this->L10N->t('Saved') : $Message));
}
示例10: viewToNodeProvider
public function viewToNodeProvider()
{
return [[function () {
Filesystem::file_put_contents('test.txt', 'asd');
}, 'preWrite'], [function () {
Filesystem::file_put_contents('test.txt', 'asd');
}, 'postWrite'], [function () {
Filesystem::file_put_contents('test.txt', 'asd');
}, 'preCreate'], [function () {
Filesystem::file_put_contents('test.txt', 'asd');
}, 'postCreate'], [function () {
Filesystem::mkdir('test.txt');
}, 'preCreate'], [function () {
Filesystem::mkdir('test.txt');
}, 'postCreate'], [function () {
Filesystem::touch('test.txt');
}, 'preTouch'], [function () {
Filesystem::touch('test.txt');
}, 'postTouch'], [function () {
Filesystem::touch('test.txt');
}, 'preCreate'], [function () {
Filesystem::touch('test.txt');
}, 'postCreate'], [function () {
Filesystem::file_put_contents('test.txt', 'asd');
Filesystem::unlink('test.txt');
}, 'preDelete'], [function () {
Filesystem::file_put_contents('test.txt', 'asd');
Filesystem::unlink('test.txt');
}, 'postDelete'], [function () {
Filesystem::mkdir('test.txt');
Filesystem::rmdir('test.txt');
}, 'preDelete'], [function () {
Filesystem::mkdir('test.txt');
Filesystem::rmdir('test.txt');
}, 'postDelete']];
}
示例11: testRename
/**
* if a folder gets renamed all children mount points should be renamed too
*/
function testRename()
{
$fileinfo = \OC\Files\Filesystem::getFileInfo($this->folder);
$share = $this->share(\OCP\Share::SHARE_TYPE_USER, $this->folder, self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_ALL);
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
// make sure that the shared folder exists
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->folder));
\OC\Files\Filesystem::mkdir('oldTarget');
\OC\Files\Filesystem::mkdir('oldTarget/subfolder');
\OC\Files\Filesystem::mkdir('newTarget');
\OC\Files\Filesystem::rename($this->folder, 'oldTarget/subfolder/' . $this->folder);
// re-login to make sure that the new mount points are initialized
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
\OC\Files\Filesystem::rename('/oldTarget', '/newTarget/oldTarget');
// re-login to make sure that the new mount points are initialized
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
$this->assertTrue(\OC\Files\Filesystem::file_exists('/newTarget/oldTarget/subfolder/' . $this->folder));
// cleanup
$this->shareManager->deleteShare($share);
}
示例12: array
$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;
}
if (strpos($foldername, '/') !== false) {
$result['data'] = array('message' => $l10n->t('Folder name must not contain "/". Please choose a different name.'));
OCP\JSON::error($result);
exit;
}
//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);
exit;
}
if (\OC\Files\Filesystem::mkdir($target)) {
if ($dir !== '/') {
$path = $dir . '/' . $foldername;
} else {
$path = '/' . $foldername;
}
$meta = \OC\Files\Filesystem::getFileInfo($path);
$id = $meta['fileid'];
OCP\JSON::success(array('data' => array('id' => $id)));
exit;
}
OCP\JSON::error(array('data' => array('message' => $l10n->t('Error when creating the folder'))));
示例13: testDelete
public function testDelete()
{
$textSize = strlen("dummy file data\n");
$imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo.png');
$rootCachedData = $this->cache->get('');
$this->assertEquals(3 * $textSize + $imageSize, $rootCachedData['size']);
$this->assertTrue($this->cache->inCache('foo.txt'));
Filesystem::unlink('foo.txt');
$this->assertFalse($this->cache->inCache('foo.txt'));
$cachedData = $this->cache->get('');
$this->assertEquals(2 * $textSize + $imageSize, $cachedData['size']);
$this->assertInternalType('string', $rootCachedData['etag']);
$this->assertInternalType('string', $cachedData['etag']);
$this->assertNotSame($rootCachedData['etag'], $cachedData['etag']);
$this->assertGreaterThanOrEqual($rootCachedData['mtime'], $cachedData['mtime']);
$rootCachedData = $cachedData;
Filesystem::mkdir('bar_folder');
$this->assertTrue($this->cache->inCache('bar_folder'));
$cachedData = $this->cache->get('');
$this->assertInternalType('string', $rootCachedData['etag']);
$this->assertInternalType('string', $cachedData['etag']);
$this->assertNotSame($rootCachedData['etag'], $cachedData['etag']);
$rootCachedData = $cachedData;
Filesystem::rmdir('bar_folder');
$this->assertFalse($this->cache->inCache('bar_folder'));
$cachedData = $this->cache->get('');
$this->assertInternalType('string', $rootCachedData['etag']);
$this->assertInternalType('string', $cachedData['etag']);
$this->assertNotSame($rootCachedData['etag'], $cachedData['etag']);
$this->assertGreaterThanOrEqual($rootCachedData['mtime'], $cachedData['mtime']);
}
示例14: ListTorrentFiles
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function ListTorrentFiles()
{
\OCP\JSON::setContentTypeHeader('application/json');
try {
if (!$this->AllowProtocolBT && !\OC_User::isAdminUser($this->CurrentUID)) {
throw new \Exception((string) $this->L10N->t('You are not allowed to use the BitTorrent protocol'));
}
if (!\OC\Files\Filesystem::is_dir($this->TorrentsFolder)) {
\OC\Files\Filesystem::mkdir($this->TorrentsFolder);
}
$this->TorrentsFolder = \OC\Files\Filesystem::normalizePath($this->TorrentsFolder);
$Files = \OCA\Files\Helper::getFiles($this->TorrentsFolder, 'name', 'desc', 'application/octet-stream');
$Files = \OCA\Files\Helper::formatFileInfos($Files);
return new JSONResponse(array('ERROR' => false, 'FILES' => $Files));
} catch (Exception $E) {
return new JSONResponse(array('ERROR' => true, 'MESSAGE' => $E->getMessage()));
}
}
示例15: Add
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function Add()
{
\OCP\JSON::setContentTypeHeader('application/json');
if (isset($_POST['FILE']) && strlen($_POST['FILE']) > 0 && Tools::CheckURL($_POST['FILE']) && isset($_POST['OPTIONS'])) {
try {
if (!$this->AllowProtocolYT && !\OC_User::isAdminUser($this->CurrentUID)) {
throw new \Exception((string) $this->L10N->t('You are not allowed to use the YouTube protocol'));
}
$YouTube = new YouTube($this->YTDLBinary, $_POST['FILE']);
if (!is_null($this->ProxyAddress) && $this->ProxyPort > 0 && $this->ProxyPort <= 65536) {
$YouTube->SetProxy($this->ProxyAddress, $this->ProxyPort);
}
if (isset($_POST['OPTIONS']['YTForceIPv4']) && strcmp($_POST['OPTIONS']['YTForceIPv4'], 'false') == 0) {
$YouTube->SetForceIPv4(false);
}
// Extract Audio YES
if (isset($_POST['OPTIONS']['YTExtractAudio']) && strcmp($_POST['OPTIONS']['YTExtractAudio'], 'true') == 0) {
$VideoData = $YouTube->GetVideoData(true);
if (!isset($VideoData['AUDIO']) || !isset($VideoData['FULLNAME'])) {
return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('Unable to retrieve true YouTube audio URL')));
}
$DL = array('URL' => $VideoData['AUDIO'], 'FILENAME' => Tools::CleanString($VideoData['FULLNAME']), 'TYPE' => 'YT Audio');
} else {
$VideoData = $YouTube->GetVideoData();
if (!isset($VideoData['VIDEO']) || !isset($VideoData['FULLNAME'])) {
return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('Unable to retrieve true YouTube video URL')));
}
$DL = array('URL' => $VideoData['VIDEO'], 'FILENAME' => Tools::CleanString($VideoData['FULLNAME']), 'TYPE' => 'YT Video');
}
// If target file exists, create a new one
if (\OC\Files\Filesystem::file_exists($this->DownloadsFolder . '/' . $DL['FILENAME'])) {
$DL['FILENAME'] = time() . '_' . $DL['FILENAME'];
}
// Create the target file if the downloader is ARIA2
if ($this->WhichDownloader == 0) {
\OC\Files\Filesystem::touch($this->DownloadsFolder . '/' . $DL['FILENAME']);
} else {
if (!\OC\Files\Filesystem::is_dir($this->DownloadsFolder)) {
\OC\Files\Filesystem::mkdir($this->DownloadsFolder);
}
}
$OPTIONS = array('dir' => $this->AbsoluteDownloadsFolder, 'out' => $DL['FILENAME']);
if (!is_null($this->ProxyAddress) && $this->ProxyPort > 0 && $this->ProxyPort <= 65536) {
$OPTIONS['all-proxy'] = rtrim($this->ProxyAddress, '/') . ':' . $this->ProxyPort;
if (!is_null($this->ProxyUser) && !is_null($this->ProxyPasswd)) {
$OPTIONS['all-proxy-user'] = $this->ProxyUser;
$OPTIONS['all-proxy-passwd'] = $this->ProxyPasswd;
}
}
if (!is_null($this->MaxDownloadSpeed) && $this->MaxDownloadSpeed > 0) {
$OPTIONS['max-download-limit'] = $this->MaxDownloadSpeed . 'K';
}
$AddURI = $this->WhichDownloader == 0 ? Aria2::AddUri(array($DL['URL']), array('Params' => $OPTIONS)) : CURL::AddUri($DL['URL'], $OPTIONS);
if (isset($AddURI['result']) && !is_null($AddURI['result'])) {
$SQL = 'INSERT INTO `*PREFIX*ocdownloader_queue` (`UID`, `GID`, `FILENAME`, `PROTOCOL`, `STATUS`, `TIMESTAMP`) VALUES (?, ?, ?, ?, ?, ?)';
if ($this->DbType == 1) {
$SQL = 'INSERT INTO *PREFIX*ocdownloader_queue ("UID", "GID", "FILENAME", "PROTOCOL", "STATUS", "TIMESTAMP") VALUES (?, ?, ?, ?, ?, ?)';
}
$Query = \OCP\DB::prepare($SQL);
$Result = $Query->execute(array($this->CurrentUID, $AddURI['result'], $DL['FILENAME'], $DL['TYPE'], 1, time()));
sleep(1);
$Status = Aria2::TellStatus($AddURI['result']);
$Progress = 0;
if ($Status['result']['totalLength'] > 0) {
$Progress = $Status['result']['completedLength'] / $Status['result']['totalLength'];
}
$ProgressString = Tools::GetProgressString($Status['result']['completedLength'], $Status['result']['totalLength'], $Progress);
return new JSONResponse(array('ERROR' => false, 'MESSAGE' => (string) $this->L10N->t('Download started'), 'GID' => $AddURI['result'], 'PROGRESSVAL' => round($Progress * 100, 2) . '%', 'PROGRESS' => is_null($ProgressString) ? (string) $this->L10N->t('N/A') : $ProgressString, 'STATUS' => isset($Status['result']['status']) ? (string) $this->L10N->t(ucfirst($Status['result']['status'])) : (string) $this->L10N->t('N/A'), 'STATUSID' => Tools::GetDownloadStatusID($Status['result']['status']), 'SPEED' => isset($Status['result']['downloadSpeed']) ? Tools::FormatSizeUnits($Status['result']['downloadSpeed']) . '/s' : (string) $this->L10N->t('N/A'), 'FILENAME' => strlen($DL['FILENAME']) > 40 ? substr($DL['FILENAME'], 0, 40) . '...' : $DL['FILENAME'], 'PROTO' => $DL['TYPE'], 'ISTORRENT' => false));
} else {
return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('Returned GID is null ! Is Aria2c running as a daemon ?')));
}
} catch (Exception $E) {
return new JSONResponse(array('ERROR' => true, 'MESSAGE' => $E->getMessage()));
}
} else {
return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('Please check the URL you\'ve just provided')));
}
}