public function getThumbnail($path)
 {
     $gallery_path = \OCP\Config::getSystemValue('datadirectory') . '/' . \OC_User::getUser() . '/gallery';
     if (file_exists($gallery_path . $path)) {
         return new \OC_Image($gallery_path . $path);
     }
     if (!\OC_Filesystem::file_exists($path)) {
         \OC_Log::write(self::TAG, 'File ' . $path . ' don\'t exists', \OC_Log::WARN);
         return false;
     }
     $image = new \OC_Image();
     $image->loadFromFile(\OC_Filesystem::getLocalFile($path));
     if (!$image->valid()) {
         return false;
     }
     $image->fixOrientation();
     $ret = $image->preciseResize(floor(150 * $image->width() / $image->height()), 150);
     if (!$ret) {
         \OC_Log::write(self::TAG, 'Couldn\'t resize image', \OC_Log::ERROR);
         unset($image);
         return false;
     }
     $image->save($gallery_path . '/' . $path);
     return $image;
 }
Example #2
0
 public static function getThumbnail($image_name, $owner = null)
 {
     if (!$owner) {
         $owner = OCP\USER::getUser();
     }
     $save_dir = OCP\Config::getSystemValue("datadirectory") . '/' . $owner . '/gallery/';
     $save_dir .= dirname($image_name) . '/';
     $image_path = $image_name;
     $thumb_file = $save_dir . basename($image_name);
     if (!is_dir($save_dir)) {
         mkdir($save_dir, 0777, true);
     }
     if (file_exists($thumb_file)) {
         $image = new OC_Image($thumb_file);
     } else {
         $image_path = OC_Filesystem::getLocalFile($image_path);
         if (!file_exists($image_path)) {
             return null;
         }
         $image = new OC_Image($image_path);
         if ($image->valid()) {
             $image->centerCrop(200);
             $image->fixOrientation();
             $image->save($thumb_file);
         }
     }
     if ($image->valid()) {
         return $image;
     } else {
         $image->destroy();
     }
     return null;
 }
 function search($query)
 {
     $files = OC_Filesystem::search($query);
     $results = array();
     foreach ($files as $file) {
         if (OC_Filesystem::is_dir($file)) {
             $results[] = new OC_Search_Result(basename($file), '', OC_Helper::linkTo('files', 'index.php?dir=' . $file), 'Files');
         } else {
             $mime = OC_Filesystem::getMimeType($file);
             $mimeBase = substr($mime, 0, strpos($mime, '/'));
             switch ($mimeBase) {
                 case 'audio':
                     break;
                 case 'text':
                     $results[] = new OC_Search_Result(basename($file), '', OC_Helper::linkTo('files', 'download.php?file=' . $file), 'Text');
                     break;
                 case 'image':
                     $results[] = new OC_Search_Result(basename($file), '', OC_Helper::linkTo('files', 'download.php?file=' . $file), 'Images');
                     break;
                 default:
                     if ($mime == 'application/xml') {
                         $results[] = new OC_Search_Result(basename($file), '', OC_Helper::linkTo('files', 'download.php?file=' . $file), 'Text');
                     } else {
                         $results[] = new OC_Search_Result(basename($file), '', OC_Helper::linkTo('files', 'download.php?file=' . $file), 'Files');
                     }
             }
         }
     }
     return $results;
 }
Example #4
0
/**
 * 
 * @param type $study_name the name of the study directory
 * @return the job id
 */
function create_execution_env($study_name, $script_name)
{
    include 'config.inc.php';
    $jobid = create_job_id($study_name, $script_name);
    $job_dir = get_job_exec_dir($jobid);
    while (is_dir($job_dir)) {
        // the sandbox directory is already existing, sleep 1 second and generate another ID
        sleep(1);
        $jobid = create_job_id($study_name, $script_name);
        $job_dir = get_job_exec_dir($jobid);
    }
    mkdir($job_dir, 0777, true);
    // [job_root_dir]/[job_id]/data --> ../../data/[fs_root]/[study_name]/data
    $datadir = $NC_CONFIG["symlink_prefix"] . "/" . $study_name . "/data";
    $pipelinedir = get_absolute_path($study_name . "/pipeline");
    $resultsdir = $NC_CONFIG["symlink_prefix"] . "/" . $study_name . "/results/" . $jobid;
    OC_Filesystem::mkdir("{$study_name}/results/{$jobid}");
    # le dir /data e /results sono link simbolici alle vere directory del caso di studio
    mkdir($job_dir . "/pipeline");
    symlink($datadir, $job_dir . "/data");
    symlink($resultsdir, $job_dir . "/results");
    # creo il file in cui verrà rediretto lo standard output
    $date = date("Y-m-d H:i:s");
    OC_Filesystem::file_put_contents(get_job_output_file($study_name, $jobid), "Standard output for job {$jobid}, run at {$date}\n");
    $jobinfo = array("jobid" => $jobid, "study" => $study_name);
    save_job_info($study_name, $jobid, $jobinfo);
    # copia gli script del caso di studio nella pipeline
    copy_dir($pipelinedir, $job_dir . "/pipeline");
    return $jobid;
}
Example #5
0
 /**
  * Compress File or Folder
  * @param $target The target to compress
  * @return Boolean  
  */
 public static function compressTarget($target)
 {
     $oc_target = OC::$CONFIG_DATADIRECTORY . $target;
     if (OC_Filesystem::is_file($target)) {
         $fileinfo = pathinfo($oc_target);
         $archiveName = $fileinfo['filename'];
         $dirTarget = $fileinfo['dirname'];
     } else {
         $archiveName = basename($oc_target);
         $dirTarget = dirname($oc_target);
     }
     $archiveName .= '.zip';
     if (file_exists($dirTarget . '/' . $archiveName)) {
         $archiveName = md5(rand()) . '_' . $archiveName;
     }
     $zip = new ZipArchive();
     if ($zip->open($dirTarget . '/' . $archiveName, ZipArchive::CREATE) === TRUE) {
         if (!is_dir($oc_target)) {
             $zip->addFile($oc_target, basename($oc_target));
         } else {
             self::addFolderToZip($oc_target, $zip, basename($oc_target) . '/');
         }
     }
     $zip->close();
 }
Example #6
0
function thumb($path)
{
    $thumb_path = \OCP\Config::getSystemValue('datadirectory') . '/' . \OC_User::getUser() . '/reader';
    if (file_exists($thumb_path . $path)) {
        return new \OC_Image($thumb_path . $path);
    }
    if (!\OC_Filesystem::file_exists($path)) {
        return false;
    }
}
Example #7
0
 public function testSimple()
 {
     $file = OC::$SERVERROOT . '/3rdparty/MDB2.php';
     $original = file_get_contents($file);
     OC_Filesystem::file_put_contents('/file', $original);
     OC_FileProxy::$enabled = false;
     $stored = OC_Filesystem::file_get_contents('/file');
     OC_FileProxy::$enabled = true;
     $fromFile = OC_Filesystem::file_get_contents('/file');
     $this->assertNotEqual($original, $stored);
     $this->assertEqual($original, $fromFile);
 }
Example #8
0
 public static function getPresentations()
 {
     $presentations = array();
     $list = \OC_FileCache::searchByMime('application', 'zip');
     foreach ($list as $l) {
         $info = pathinfo($l);
         $size = \OC_Filesystem::filesize($l);
         $mtime = \OC_Filesystem::filemtime($l);
         $entry = array('url' => $l, 'name' => $info['filename'], 'size' => $size, 'mtime' => $mtime);
         $presentations[] = $entry;
     }
     return $presentations;
 }
Example #9
0
 /**
  * This method is called before any HTTP method and forces users to be authenticated
  *
  * @param string $method
  * @throws Sabre_DAV_Exception
  * @return bool
  */
 public function checkQuota($uri, $data = null)
 {
     $expected = $this->server->httpRequest->getHeader('X-Expected-Entity-Length');
     $length = $expected ? $expected : $this->server->httpRequest->getHeader('Content-Length');
     if ($length) {
         if (substr($uri, 0, 1) !== '/') {
             $uri = '/' . $uri;
         }
         list($parentUri, $newName) = Sabre_DAV_URLUtil::splitPath($uri);
         if ($length > OC_Filesystem::free_space($parentUri)) {
             throw new Sabre_DAV_Exception('Quota exceeded. File is too big.');
         }
     }
     return true;
 }
 public static function createDataScope($appUrl, $userAddress, $dataScope)
 {
     $token = uniqid();
     self::addToken($token, $appUrl, $userAddress, $dataScope);
     //TODO: input checking on $userAddress and $dataScope
     list($userName, $userHost) = explode('@', $userAddress);
     OC_Util::setupFS(OC_User::getUser());
     $scopePathParts = array('remoteStorage', 'webdav', $userHost, $userName, $dataScope);
     for ($i = 0; $i <= count($scopePathParts); $i++) {
         $thisPath = '/' . implode('/', array_slice($scopePathParts, 0, $i));
         if (!OC_Filesystem::file_exists($thisPath)) {
             OC_Filesystem::mkdir($thisPath);
         }
     }
     return $token;
 }
Example #11
0
function getID($path)
{
    // use the share table from the db to find the item source if the file was reshared because shared files
    //are not stored in the file cache.
    if (substr(OC_Filesystem::getMountPoint($path), -7, 6) == "Shared") {
        $path_parts = explode('/', $path, 5);
        $user = $path_parts[1];
        $intPath = '/' . $path_parts[4];
        $query = \OC_DB::prepare('SELECT `item_source` FROM `*PREFIX*share` WHERE `uid_owner` = ? AND `file_target` = ? ');
        $result = $query->execute(array($user, $intPath));
        $row = $result->fetchRow();
        $fileSource = $row['item_source'];
    } else {
        $fileSource = OC_Filecache::getId($path, '');
    }
    return $fileSource;
}
Example #12
0
 public static function createCategories($appUrl, $categories)
 {
     $token = uniqid();
     OC_Util::setupFS(OC_User::getUser());
     self::addToken($token, $appUrl, $categories);
     foreach (explode(',', $categories) as $category) {
         //TODO: input checking on $category
         $scopePathParts = array('remoteStorage', $category);
         for ($i = 0; $i <= count($scopePathParts); $i++) {
             $thisPath = '/' . implode('/', array_slice($scopePathParts, 0, $i));
             if (!OC_Filesystem::file_exists($thisPath)) {
                 OC_Filesystem::mkdir($thisPath);
             }
         }
     }
     return base64_encode('remoteStorage:' . $token);
 }
Example #13
0
 /**
  * get all files and folders in a folder
  * @param string path
  * @param string root (optional)
  * @return array
  *
  * returns an array of assiciative arrays with the following keys:
  * - path
  * - name
  * - size
  * - mtime
  * - ctime
  * - mimetype
  * - encrypted
  * - versioned
  */
 public static function getFolderContent($path, $root = false, $mimetype_filter = '')
 {
     if ($root === false) {
         $root = OC_Filesystem::getRoot();
     }
     $parent = OC_FileCache::getId($path, $root);
     if ($parent == -1) {
         return array();
     }
     $query = OC_DB::prepare('SELECT `id`,`path`,`name`,`ctime`,`mtime`,`mimetype`,`size`,`encrypted`,`versioned`,`writable` FROM `*PREFIX*fscache` WHERE `parent`=? AND (`mimetype` LIKE ? OR `mimetype` = ?)');
     $result = $query->execute(array($parent, $mimetype_filter . '%', 'httpd/unix-directory'))->fetchAll();
     if (is_array($result)) {
         return $result;
     } else {
         OC_Log::write('files', 'getFolderContent(): file not found in cache (' . $path . ')', OC_Log::DEBUG);
         return false;
     }
 }
Example #14
0
function handleStoreSettings($root, $order)
{
    if (!OC_Filesystem::file_exists($root)) {
        OCP\JSON::error(array('cause' => 'No such file or directory'));
        return;
    }
    if (!OC_Filesystem::is_dir($root)) {
        OCP\JSON::error(array('cause' => $root . ' is not a directory'));
        return;
    }
    $current_root = OCP\Config::getUserValue(OCP\USER::getUser(), 'gallery', 'root', '/');
    $root = trim($root);
    $root = rtrim($root, '/') . '/';
    $rescan = $current_root == $root ? 'no' : 'yes';
    OCP\Config::setUserValue(OCP\USER::getUser(), 'gallery', 'root', $root);
    OCP\Config::setUserValue(OCP\USER::getUser(), 'gallery', 'order', $order);
    OCP\JSON::success(array('rescan' => $rescan));
}
Example #15
0
 /**
  * get the free space in the path's owner home folder
  * @param path
  * @return int
  */
 private function getFreeSpace($path)
 {
     $storage = OC_Filesystem::getStorage($path);
     $owner = $storage->getOwner($path);
     $totalSpace = $this->getQuota($owner);
     if ($totalSpace == -1) {
         return -1;
     }
     $rootInfo = OC_FileCache::get('', "/" . $owner . "/files");
     // TODO Remove after merge of share_api
     if (OC_FileCache::inCache('/Shared', "/" . $owner . "/files")) {
         $sharedInfo = OC_FileCache::get('/Shared', "/" . $owner . "/files");
     } else {
         $sharedInfo = null;
     }
     $usedSpace = isset($rootInfo['size']) ? $rootInfo['size'] : 0;
     $usedSpace = isset($sharedInfo['size']) ? $usedSpace - $sharedInfo['size'] : $usedSpace;
     return $totalSpace - $usedSpace;
 }
Example #16
0
 /**
  * Compress File or Folder
  * @param $target The target to compress
  * @return Boolean  
  */
 public static function compressTarget($target)
 {
     $oc_target = OC::$CONFIG_DATADIRECTORY . $target;
     if (OC_Filesystem::is_file($target)) {
         $fileinfo = pathinfo($oc_target);
         $archiveName = $fileinfo['filename'];
         $dirTarget = $fileinfo['dirname'];
     } else {
         $archiveName = basename($oc_target);
         $dirTarget = dirname($oc_target);
     }
     $archiveName .= '.tar';
     if (file_exists($dirTarget . '/' . $archiveName)) {
         $archiveName = md5(rand()) . '_' . $archiveName;
     }
     require_once '../config/config.php';
     exec($_CompressConf['tar_bin_path'] . " cf " . $dirTarget . '/' . $archiveName . " " . $oc_target);
     exec($_CompressConf['gzip_bin_path'] . " -9 " . $dirTarget . '/' . $archiveName);
 }
Example #17
0
 public static function loadUserMountPoints($user)
 {
     $user_dir = '/' . $user . '/files';
     $user_root = OC_User::getHome($user);
     $userdirectory = $user_root . '/files';
     if (is_file($user_root . '/mount.php')) {
         $mountConfig = (include $user_root . '/mount.php');
         if (isset($mountConfig['user'][$user])) {
             foreach ($mountConfig['user'][$user] as $mountPoint => $options) {
                 OC_Filesystem::mount($options['class'], $options['options'], $mountPoint);
             }
         }
         $mtime = filemtime($user_root . '/mount.php');
         $previousMTime = OC_Preferences::getValue($user, 'files', 'mountconfigmtime', 0);
         if ($mtime > $previousMTime) {
             //mount config has changed, filecache needs to be updated
             OC_FileCache::triggerUpdate($user);
             OC_Preferences::setValue($user, 'files', 'mountconfigmtime', $mtime);
         }
     }
 }
Example #18
0
 public function setUp()
 {
     //clear all proxies and hooks so we can do clean testing
     OC_FileProxy::clearProxies();
     OC_Hook::clear('OC_Filesystem');
     //enable only the encryption hook if needed
     if (OC_App::isEnabled('files_encryption')) {
         OC_FileProxy::register(new OC_FileProxy_Encryption());
     }
     //set up temporary storage
     OC_Filesystem::clearMounts();
     OC_Filesystem::mount('OC_Filestorage_Temporary', array(), '/');
     OC_User::clearBackends();
     OC_User::useBackend(new OC_User_Dummy());
     //login
     OC_User::createUser('test', 'test');
     $this->user = OC_User::getUser();
     OC_User::setUserId('test');
     //set up the users dir
     $rootView = new OC_FilesystemView('');
     $rootView->mkdir('/test');
     $this->instance = new OC_Cache_File();
 }
Example #19
0
 /**
  * @param $path
  * @param $data
  * @return bool
  */
 public function preFile_put_contents($path, &$data)
 {
     if (self::shouldEncrypt($path)) {
         if (!is_resource($data)) {
             // get root view
             $view = new \OC_FilesystemView('/');
             // get relative path
             $relativePath = \OCA\Encryption\Helper::stripUserFilesPath($path);
             if (!isset($relativePath)) {
                 return true;
             }
             // create random cache folder
             $cacheFolder = rand();
             $path_slices = explode('/', \OC_Filesystem::normalizePath($path));
             $path_slices[2] = "cache/" . $cacheFolder;
             $tmpPath = implode('/', $path_slices);
             $handle = fopen('crypt://' . $tmpPath, 'w');
             if (is_resource($handle)) {
                 // write data to stream
                 fwrite($handle, $data);
                 // close stream
                 fclose($handle);
                 // disable encryption proxy to prevent recursive calls
                 $proxyStatus = \OC_FileProxy::$enabled;
                 \OC_FileProxy::$enabled = false;
                 // get encrypted content
                 $data = $view->file_get_contents($tmpPath);
                 // remove our temp file
                 $view->deleteAll('/' . \OCP\User::getUser() . '/cache/' . $cacheFolder);
                 // re-enable proxy - our work is done
                 \OC_FileProxy::$enabled = $proxyStatus;
             }
         }
     }
     return true;
 }
Example #20
0
 /**
  * abstraction for running most basic operations
  * @param string $operation
  * @param string #path
  * @param array (optional) hooks
  * @param mixed (optional) $extraParam
  * @return mixed
  */
 private function basicOperation($operation, $path, $hooks = array(), $extraParam = null)
 {
     $absolutePath = $this->getAbsolutePath($path);
     if (OC_FileProxy::runPreProxies($operation, $absolutePath, $extraParam) and OC_Filesystem::isValidPath($path)) {
         $path = $this->getRelativePath($absolutePath);
         if ($path == null) {
             return false;
         }
         $internalPath = $this->getInternalPath($path);
         $run = true;
         if (OC_Filesystem::$loaded and $this->fakeRoot == OC_Filesystem::getRoot()) {
             foreach ($hooks as $hook) {
                 if ($hook != 'read') {
                     OC_Hook::emit(OC_Filesystem::CLASSNAME, $hook, array(OC_Filesystem::signal_param_path => $path, OC_Filesystem::signal_param_run => &$run));
                 } else {
                     OC_Hook::emit(OC_Filesystem::CLASSNAME, $hook, array(OC_Filesystem::signal_param_path => $path));
                 }
             }
         }
         if ($run and $storage = $this->getStorage($path)) {
             if (!is_null($extraParam)) {
                 $result = $storage->{$operation}($internalPath, $extraParam);
             } else {
                 $result = $storage->{$operation}($internalPath);
             }
             $result = OC_FileProxy::runPostProxies($operation, $this->getAbsolutePath($path), $result);
             if (OC_Filesystem::$loaded and $this->fakeRoot == OC_Filesystem::getRoot()) {
                 if ($operation != 'fopen') {
                     //no post hooks for fopen, the file stream is still open
                     foreach ($hooks as $hook) {
                         if ($hook != 'read') {
                             OC_Hook::emit(OC_Filesystem::CLASSNAME, 'post_' . $hook, array(OC_Filesystem::signal_param_path => $path));
                         }
                     }
                 }
             }
             return $result;
         }
     }
     return null;
 }
 public function preCopy($path1, $path2)
 {
     return OC_Filesystem::filesize($path1) < $this->getFreeSpace() or $this->getFreeSpace() == 0;
 }
Example #22
0
 /**
  * clear all mounts and storage backends
  */
 public static function clearMounts()
 {
     self::$mounts = array();
     self::$storages = array();
 }
Example #23
0
 public function file_assemble($path)
 {
     $absolutePath = OC_Filesystem::normalizePath(OC_Filesystem::getView()->getAbsolutePath($path));
     $data = '';
     // use file_put_contents as method because that best matches what this function does
     if (OC_FileProxy::runPreProxies('file_put_contents', $absolutePath, $data) && OC_Filesystem::isValidPath($path)) {
         $path = OC_Filesystem::getView()->getRelativePath($absolutePath);
         $exists = OC_Filesystem::file_exists($path);
         $run = true;
         if (!$exists) {
             OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_create, array(OC_Filesystem::signal_param_path => $path, OC_Filesystem::signal_param_run => &$run));
         }
         OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_write, array(OC_Filesystem::signal_param_path => $path, OC_Filesystem::signal_param_run => &$run));
         if (!$run) {
             return false;
         }
         $target = OC_Filesystem::fopen($path, 'w');
         if ($target) {
             $count = $this->assemble($target);
             fclose($target);
             if (!$exists) {
                 OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_create, array(OC_Filesystem::signal_param_path => $path));
             }
             OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_write, array(OC_Filesystem::signal_param_path => $path));
             OC_FileProxy::runPostProxies('file_put_contents', $absolutePath, $count);
             return $count > 0;
         } else {
             return false;
         }
     }
 }
Example #24
0
 /**
  * Adds a suffix to the name in case the file exists
  *
  * @param $path
  * @param $filename
  * @return string
  */
 public static function buildNotExistingFileName($path, $filename)
 {
     if ($path === '/') {
         $path = '';
     }
     if ($pos = strrpos($filename, '.')) {
         $name = substr($filename, 0, $pos);
         $ext = substr($filename, $pos);
     } else {
         $name = $filename;
     }
     $newpath = $path . '/' . $filename;
     $newname = $filename;
     $counter = 2;
     while (OC_Filesystem::file_exists($newpath)) {
         $newname = $name . ' (' . $counter . ')' . $ext;
         $newpath = $path . '/' . $newname;
         $counter++;
     }
     return $newpath;
 }
Example #25
0
 /**
  * pull a file from a remote server
  * @param  string  source
  * @param  string  token
  * @param  string  dir
  * @param  string  file
  * @return string  guessed mime type
  */
 static function pull($source, $token, $dir, $file)
 {
     $tmpfile = tempnam(get_temp_dir(), 'remoteCloudFile');
     $fp = fopen($tmpfile, 'w+');
     $url = $source .= "/files/pull.php?token={$token}";
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_FILE, $fp);
     curl_exec($ch);
     fclose($fp);
     $info = curl_getinfo($ch);
     $httpCode = $info['http_code'];
     curl_close($ch);
     if ($httpCode == 200 or $httpCode == 0) {
         OC_Filesystem::fromTmpFile($tmpfile, $dir . '/' . $file);
         return true;
     } else {
         return false;
     }
 }
Example #26
0
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
// Init owncloud
// Check if we are a user
OCP\JSON::checkLoggedIn();
// Set the session key for the file we are about to edit.
$dir = isset($_GET['dir']) ? $_GET['dir'] : '';
$filename = isset($_GET['file']) ? $_GET['file'] : '';
if (!empty($filename)) {
    $path = $dir . '/' . $filename;
    if (OC_Filesystem::is_writable($path)) {
        $mtime = OC_Filesystem::filemtime($path);
        $filecontents = OC_Filesystem::file_get_contents($path);
        $filecontents = iconv(mb_detect_encoding($filecontents), "UTF-8", $filecontents);
        OCP\JSON::success(array('data' => array('filecontents' => $filecontents, 'write' => 'true', 'mtime' => $mtime)));
    } else {
        $mtime = OC_Filesystem::filemtime($path);
        $filecontents = OC_Filesystem::file_get_contents($path);
        $filecontents = iconv(mb_detect_encoding($filecontents), "UTF-8", $filecontents);
        OCP\JSON::success(array('data' => array('filecontents' => $filecontents, 'write' => 'false', 'mtime' => $mtime)));
    }
} else {
    OCP\JSON::error(array('data' => array('message' => 'Invalid file path supplied.')));
}
Example #27
0
 /**
  * @brief update file cache with the new unencrypted size after file was written
  * @param string $path
  * @param mixed $result
  * @return mixed
  */
 public function postFile_put_contents($path, $result)
 {
     $normalizedPath = \OC_Filesystem::normalizePath($path);
     if (isset(self::$unencryptedSizes[$normalizedPath])) {
         $view = new \OC_FilesystemView('/');
         $view->putFileInfo($normalizedPath, array('encrypted' => true, 'unencrypted_size' => self::$unencryptedSizes[$normalizedPath]));
         unset(self::$unencryptedSizes[$normalizedPath]);
     }
     return $result;
 }
 public static function play($params)
 {
     $username = !self::checkAuth($params);
     if ($username) {
         echo "<root>\n\t<error code='400'>Invalid login</error>\n</root>";
         return;
     }
     if ($song = OC_MEDIA_COLLECTION::getSong($params['song'])) {
         OC_Util::setupFS($song["song_user"]);
         header('Content-type: ' . OC_Filesystem::getMimeType($song['song_path']));
         header('Content-Length: ' . $song['song_size']);
         OC_Filesystem::readfile($song['song_path']);
     }
 }
Example #29
0
 /**
  * Returns the mime-type for a file
  *
  * If null is returned, we'll assume application/octet-stream
  *
  * @return mixed
  */
 public function getContentType()
 {
     return OC_Filesystem::getMimeType($this->path);
 }
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*
*/
// Init owncloud
// Check if we are a user
OCP\User::checkLoggedIn();
$filename = $_GET["file"];
if (!OC_Filesystem::file_exists($filename)) {
    header("HTTP/1.0 404 Not Found");
    $tmpl = new OCP\Template('', '404', 'guest');
    $tmpl->assign('file', $filename);
    $tmpl->printPage();
    exit;
}
$ftype = OC_Filesystem::getMimeType($filename);
header('Content-Type:' . $ftype);
header('Content-Disposition: attachment; filename="' . basename($filename) . '"');
OCP\Response::disableCaching();
header('Content-Length: ' . OC_Filesystem::filesize($filename));
@ob_end_clean();
OC_Filesystem::readfile($filename);