Changeset View
Changeset View
Standalone View
Standalone View
lib/drivers/seafile/seafile_api.php
Show First 20 Lines • Show All 549 Lines • ▼ Show 20 Lines | class seafile_api | ||||
public function file_upload($repo_id, $filename, $file) | public function file_upload($repo_id, $filename, $file) | ||||
{ | { | ||||
if ($repo_id === '' || !is_string($repo_id)) { | if ($repo_id === '' || !is_string($repo_id)) { | ||||
$this->status = self::BAD_REQUEST; | $this->status = self::BAD_REQUEST; | ||||
return false; | return false; | ||||
} | } | ||||
// first get upload link | // first get upload link | ||||
$result = $this->request('GET', "repos/$repo_id/upload-link"); | $parent_dir = '/'; | ||||
$result = $this->request('GET', "repos/$repo_id/upload-link/?p=$parent_dir"); | |||||
if ($this->is_error() || empty($result)) { | if ($this->is_error() || empty($result)) { | ||||
return false; | return false; | ||||
} | } | ||||
$path = explode('/', $filename); | $path = explode('/', $filename); | ||||
$filename = array_pop($path); | $filename = array_pop($path); | ||||
$dir = '/' . ltrim(implode('/', $path), '/'); | $dir = ltrim(implode('/', $path), '/'); | ||||
$file['name'] = $filename; | $file['name'] = $filename; | ||||
// then update file | // then update file | ||||
$result = $this->request('POST', $result, null, array( | $result = $this->request('POST', $result, null, array( | ||||
'parent_dir' => $dir | 'parent_dir' => $parent_dir, | ||||
'relative_path' => $dir | |||||
), | ), | ||||
array('file' => $file) | array('file' => $file) | ||||
); | ); | ||||
return $this->is_error() === false; | return $this->is_error() === false; | ||||
} | } | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 824 Lines • Show Last 20 Lines |