<?php

error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

include 'fonction.php';

$root = $_SERVER["DOCUMENT_ROOT"];

$directory = "/uploads/";

$absolute_directory = "$root$directory";

if(is_dir($absolute_directory)) {
    $absolute_directory = $absolute_directory . "/";
}
else {
	
	if(file_exists($absolute_directory)) {
		header("HTTP/1.1 500 File exists in " . $absolute_directory);
		exit(1);
	}
	else {
		mkdir($absolute_directory);
	}
}



$files = scandir($absolute_directory);

$files_array = array ();

foreach($files as $file) {
	if (is_file($absolute_directory.$file)) {
		$size = filesize($absolute_directory.$file);
		$title = $file.' '.formatBytes($size);
		$file_array = array(
			'name' => $file,
			'href' => $directory.$file,
			'size' => $size,
			'mime' => mime_type($absolute_directory.$file),
			'type' => font_type($absolute_directory.$file)
		);
		array_push($files_array, $file_array);
	}
} 

echo json_encode($files_array);

?>
