Ejemplo n.º 1
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;
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * create a new file or folder
  *
  * @param dir  $dir
  * @param file $name
  * @param type $type
  */
 public static function newFile($dir, $name, $type)
 {
     if (OC_User::isLoggedIn()) {
         $file = $dir . '/' . $name;
         if ($type == 'dir') {
             return OC_Filesystem::mkdir($file);
         } elseif ($type == 'file') {
             $fileHandle = OC_Filesystem::fopen($file, 'w');
             if ($fileHandle) {
                 fclose($fileHandle);
                 return true;
             } else {
                 return false;
             }
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Returns the data
  *
  * @return string
  */
 public function get()
 {
     return OC_Filesystem::fopen($this->path, 'r');
 }
 /**
  * Get the file by an URL
  * @param URL of the file
  */
 public static function getHttpFile($file, $pr_transfer = NULL)
 {
     try {
         if (!self::remoteFileExists($file)) {
             return 'The file does not exists ...';
         }
         if (!isset($pr_transfer)) {
             $fileinfo = pathinfo($file);
         } else {
             $fileinfo = pathinfo($pr_transfer);
         }
         $filename = strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') ? preg_replace('/\\./', '%2e', $fileinfo['basename'], substr_count($fileinfo['basename'], '.') - 1) : $fileinfo['basename'];
         if (strpos($filename, 'rsapi.cgi')) {
             $filename = substr($filename, 0, strpos($filename, '&'));
         }
         if (OC_Filesystem::file_exists('/Downloads/' . $filename)) {
             $filename = md5(rand()) . '_' . $filename;
         }
         $fs = OC_Filesystem::fopen('/Downloads/' . $filename, 'w');
         $size = self::getRemoteFileSize($file);
         if ($size == 0) {
             return 'Error ! Null file size.';
         }
         switch (strtolower($fileinfo['extension'])) {
             case 'exe':
                 $ctype = 'application/octet-stream';
                 break;
             case 'zip':
                 $ctype = 'application/zip';
                 break;
             case 'mp3':
                 $ctype = 'audio/mpeg';
                 break;
             case 'mpg':
                 $ctype = 'video/mpeg';
                 break;
             case 'avi':
                 $ctype = 'video/x-msvideo';
                 break;
             case 'png':
                 $ctype = 'image/png';
                 break;
             default:
                 $ctype = 'application/force-download';
         }
         $seek_end = empty($seek_end) ? $size - 1 : min(abs(intval($seek_end)), $size - 1);
         $seek_start = empty($seek_start) || $seek_end < abs(intval($seek_start)) ? 0 : max(abs(intval($seek_start)), 0);
         /*header("Cache-Control: cache, must-revalidate");  
           header("Pragma: public");
           header('Content-Type: ' . $ctype);
           header('Content-Disposition: attachment; filename="' . $filename . '"');
           header('Content-Length: ' . ($seek_end - $seek_start + 1));*/
         $fp = fopen($file, 'rb');
         set_time_limit(0);
         while (!feof($fp)) {
             $data = fread($fp, 1024 * 8);
             if ($data == '') {
                 break;
             }
             fwrite($fs, $data);
         }
         fclose($fp);
         fclose($fs);
         return array('ok' => 'Transfer completed successfully. The file has been moved in your Downloads folder.');
     } catch (exception $e) {
         return array('error' => $e->getMessage());
     }
 }
Ejemplo n.º 5
0
        header('WWW-Authenticate: Basic realm="ownCloud Server"');
        header('HTTP/1.0 401 Unauthorized');
        echo 'Valid credentials must be supplied';
        exit;
    } else {
        if (!OC_User::login($_SERVER["PHP_AUTH_USER"], $_SERVER["PHP_AUTH_PW"])) {
            exit;
        }
    }
}
list($type, $file) = explode('/', substr($path_info, 1 + strlen($service) + 1), 2);
if ($type != 'oc_chunked') {
    OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND);
    die;
}
if (!OC_Filesystem::is_file($file)) {
    OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND);
    die;
}
switch ($_SERVER['REQUEST_METHOD']) {
    case 'PUT':
        $input = fopen("php://input", "r");
        $org_file = OC_Filesystem::fopen($file, 'rb');
        $info = array('name' => basename($file));
        $sync = new OC_FileChunking($info);
        $result = $sync->signature_split($org_file, $input);
        echo json_encode($result);
        break;
    default:
        OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND);
}
Ejemplo n.º 6
0
 * All rights reserved
 */
$filename = $_POST['filename'];
$json = false;
if (isset($_POST['json'])) {
    $json = (bool) $_POST["json"];
}
/*
 * max size of output file, to avoid reading a very big output and clogging the network
 */
$MAX_SIZE = 1024 * 512;
# "512k of memory should be enough for everyone"
$content = "";
if (OC_Filesystem::is_file($filename) && OC_Filesystem::is_readable($filename)) {
    if (OC_Filesystem::filesize($filename) > $MAX_SIZE) {
        $handle = OC_Filesystem::fopen($filename, "r");
        if ($handle) {
            $content = fread($handle, $MAX_SIZE);
            fclose($handle);
        }
    } else {
        $content = OC_Filesystem::file_get_contents($filename);
    }
} else {
    echo "ERROR: Cannot read " . $filename;
}
if ($json) {
    $json_obj = json_decode($content);
    foreach ($json_obj as $key => $value) {
        echo "{$key} : {$value}\n";
    }