Ejemplo n.º 1
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;
     }
 }
Ejemplo n.º 2
0
        exit;
    }
}
$files = $_FILES['files'];
$dir = $_POST['dir'];
$error = '';
$totalSize = 0;
foreach ($files['size'] as $size) {
    $totalSize += $size;
}
if ($totalSize > OC_Filesystem::free_space('/')) {
    OCP\JSON::error(array("data" => array("message" => "Not enough space available")));
    exit;
}
$result = array();
if (strpos($dir, '..') === false) {
    $fileCount = count($files['name']);
    for ($i = 0; $i < $fileCount; $i++) {
        $target = OCP\Files::buildNotExistingFileName(stripslashes($dir), $files['name'][$i]);
        if (is_uploaded_file($files['tmp_name'][$i]) and OC_Filesystem::fromTmpFile($files['tmp_name'][$i], $target)) {
            $meta = OC_FileCache::get($target);
            $id = OC_FileCache::getId($target);
            $result[] = array("status" => "success", 'mime' => $meta['mimetype'], 'size' => $meta['size'], 'id' => $id, 'name' => basename($target));
        }
    }
    OCP\JSON::encodedPrint($result);
    exit;
} else {
    $error = 'invalid dir';
}
OCP\JSON::error(array('data' => array('error' => $error, "file" => $fileName)));