);
if(trim($filename) === '') {
- $result['data'] = array('message' => $l10n->t('File name cannot be empty.'));
+ $result['data'] = array('message' => (string)$l10n->t('File name cannot be empty.'));
OCP\JSON::error($result);
exit();
}
if(strpos($filename, '/') !== false) {
- $result['data'] = array('message' => $l10n->t('File name must not contain "/". Please choose a different name.'));
+ $result['data'] = array('message' => (string)$l10n->t('File name must not contain "/". Please choose a different name.'));
OCP\JSON::error($result);
exit();
}
$target = $dir.'/'.$filename;
if (\OC\Files\Filesystem::file_exists($target)) {
- $result['data'] = array('message' => $l10n->t(
+ $result['data'] = array('message' => (string)$l10n->t(
'The name %s is already used in the folder %s. Please choose a different name.',
array($filename, $dir))
);
if($source) {
if(substr($source, 0, 8)!='https://' and substr($source, 0, 7)!='http://') {
- OCP\JSON::error(array('data' => array( 'message' => $l10n->t('Not a valid source') )));
+ OCP\JSON::error(array('data' => array('message' => $l10n->t('Not a valid source'))));
+ exit();
+ }
+
+ if (!ini_get('allow_url_fopen')) {
+ $eventSource->send('error', array('message' => $l10n->t('Server is not allowed to open URLs, please check the server configuration')));
+ $eventSource->close();
exit();
}
$ctx = stream_context_create(null, array('notification' =>'progress'));
- $sourceStream=fopen($source, 'rb', false, $ctx);
- $result=\OC\Files\Filesystem::file_put_contents($target, $sourceStream);
+ $sourceStream=@fopen($source, 'rb', false, $ctx);
+ $result = 0;
+ if (is_resource($sourceStream)) {
+ $result=\OC\Files\Filesystem::file_put_contents($target, $sourceStream);
+ }
if($result) {
$meta = \OC\Files\Filesystem::getFileInfo($target);
$mime=$meta['mimetype'];
$id = $meta['fileid'];
- $eventSource->send('success', array('mime'=>$mime, 'size'=>\OC\Files\Filesystem::filesize($target), 'id' => $id, 'etag' => $meta['etag']));
+ $eventSource->send('success', array('mime' => $mime, 'size' => \OC\Files\Filesystem::filesize($target), 'id' => $id, 'etag' => $meta['etag']));
} else {
- $eventSource->send('error', $l10n->t('Error while downloading %s to %s', array($source, $target)));
+ $eventSource->send('error', array('message' => $l10n->t('Error while downloading %s to %s', array($source, $target))));
+ }
+ if (is_resource($sourceStream)) {
+ fclose($sourceStream);
}
$eventSource->close();
exit();
}
if($this->fallback) {
$response='<script type="text/javascript">window.parent.OC.EventSource.fallBackCallBack('
- .$this->fallBackId.',"'.$type.'",'.json_encode($data).')</script>'.PHP_EOL;
+ .$this->fallBackId.',"' . $type . '",' . OCP\JSON::encode($data) . ')</script>' . PHP_EOL;
echo $response;
}else{
if($type) {
- echo 'event: '.$type.PHP_EOL;
+ echo 'event: ' . $type.PHP_EOL;
}
- echo 'data: '.json_encode($data).PHP_EOL;
+ echo 'data: ' . OCP\JSON::encode($data) . PHP_EOL;
}
echo PHP_EOL;
flush();