server/files/ajax/upload.php

34 lines
973 B
PHP
Raw Normal View History

2011-04-16 21:18:06 +00: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-16 21:18:06 +00: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)){
echo json_encode(array( "status" => "success", 'mime'=>OC_FILESYSTEM::getMimeType($target),'size'=>OC_FILESYSTEM::filesize($target)));
2011-04-16 21:18:06 +00:00
exit();
}
}
2011-04-16 21:28:50 +00:00
$error = $_FILES['file']['error'];
2011-04-19 07:13:50 +00:00
echo json_encode(array( 'status' => 'error', 'data' => array('error' => $error, "file" => $fileName)));
2011-04-16 21:18:06 +00:00
?>