nextcloud/files/ajax/upload.php

34 lines
887 B
PHP
Raw Normal View History

2011-04-17 01:18:06 +04:00
<?php
// Init owncloud
require_once('../../lib/base.php');
// We send json data
// header( "Content-Type: application/json" );
// Firefox and Konqueror tries to download application/json for me. --Arthur
header( "Content-Type: text/plain" );
// Check if we are a user
if( !OC_USER::isLoggedIn()){
echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" )));
2011-04-17 01:18:06 +04:00
exit();
}
$fileName=$_FILES['file']['name'];
$source=$_FILES['file']['tmp_name'];
$dir = $_POST['dir'];
if(!empty($dir)) $dir .= '/';
$target='/' . stripslashes($dir) . $fileName;
if(strpos($dir,'..') === false){
if(OC_FILESYSTEM::fromUploadedFile($source,$target)){
2011-04-17 01:18:06 +04:00
echo json_encode(array( "status" => "success"));
exit();
}
}
2011-04-17 01:28:50 +04:00
$error = $_FILES['file']['error'];
2011-04-19 11:13:50 +04:00
echo json_encode(array( 'status' => 'error', 'data' => array('error' => $error, "file" => $fileName)));
2011-04-17 01:18:06 +04:00
?>