Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 37 additions & 52 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,76 +1,61 @@
`#html` `#css` `#js` `#php` `#master-in-software-engineering`
# File System explorer 📁

# PHP Local FileSystem explorer <!-- omit in toc -->
In this project we made a file system manager where you can create, modify and delete files and folders.

<p>
<img alt="Version" src="https://img.shields.io/badge/version-1.0-blue.svg?cacheSeconds=2592000" />
</p>
## Documentation 📋

>In this project you will have to create a system file explorer that allows the user to navigate, create directories and upload files in the same way as he would in his usual operating system.
Here we allocate all our documentes related to the project. Also there are files related to MVC pattern.

>The file explorer is a tool that allows you to directly view and manipulate the files and directories associated with a path, so you must take into account from which path the user starts and which path they can access.
- [Google Slide](https://docs.google.com/presentation/d/1n7jquvSCbY8NQCoDNMlEhuPCda0rXvcUKNP8slYYhBY/edit?usp=sharing)
- [useCase.drawio](https://drive.google.com/file/d/1h6NfXHpgnrK7r7wzWNbd0U-mS1tFE_ET/view?usp=sharing)
- [MVC documentaion](https://docs.google.com/document/d/1idHQrTkUZaREq1hbpX1Y0NTLs2Bc-GRdyV388erAAy0/edit?usp=sharing)
- [Github project with MVC](https://github.com/Cherrerotinoco/filesystem-explorer)
## Authors 🧑‍💻

Developed by:

## Index <!-- omit in toc -->
- [@Cherrerotinoco](https://github.com/Cherrerotinoco)
- [@Paola3stefania](https://github.com/Paola3stefania)
- [@andarbech](https://github.com/andarbech)
- [@sanadriu](https://github.com/sanadriu)

- [Requirements](#requirements)
- [Repository](#repository)
- [Technologies used](#technologies-used)
- [Project delivery](#project-delivery)
- [Resources](#resources)

## Requirements

- You cannot use file third-party libraries
- You will not be able to use global variables in PHP.
- You must use GIT
- You must use the PHP > v7
- Create a clear and orderly directory structure
- Both the code and the comments must be written in English
- Use the camelCase code style to define variables and functions
- In the case of using HTML, never use inline styles
- In the case of using different programming languages ​​always define the implementation in separate terms
- Remember that it is important to divide the tasks into several sub-tasks so that in this way you can associate each particular step of the construction with a specific commit
- You should try as much as possible that the commits and the planned tasks are the same
Delete files that are not used or are not necessary to evaluate the project
# C H A N G E S
### code in script in layout/table.php
--- Code change in layouts/table.php

## Repository
$.extend( true, $.fn.dataTable.defaults, {
"searching": false,
} );

First of all you must fork this project into your GitHub account.
https://datatables.net/examples/advanced_init/defaults.html

To create a fork on GitHub is as easy as clicking the “fork” button on the repository page.

<img src="https://docs.github.com/assets/images/help/repository/fork_button.jpg" alt="Fork on GitHub" width='450'>
### addon html layout of searchbar from bootstrap 5

## Technologies used
--- Code change in layouts/searchs.php

\* HTML
https://mdbootstrap.com/docs/standard/forms/search/

\* CSS

\* JS
### insert function of search Bar

\* PHP
---- Code in index.php , header section, before headcrumbs => renderSearch();

## Project delivery
### defining the action in action folders

To deliver this project you must follow the steps indicated in the document:

- [Submitting a solution](https://www.notion.so/Submitting-a-solution-524dab1a71dd4b96903f26385e24cdb6)
---- Code in SearchFile , index.php

- You must include the project documentation in PDF format.
- You must include a presentation in PDF format explaining:
- Comparison of the original design (Wireframe) with the final result of the project
- Comparison of the use case diagram with the actions that the user can finally perform
- Comparison of the original use case diagram with the final user actions
- What lessons you’ve learned during this project
- What problems have you encountered when developing this project?
- How you have organized and distributed the tasks

=======
# Modal Edit File

## Resources

- [File system](https://es.wikipedia.org/wiki/Administrador_de_archivos)
- [PHP FileSystem W3C](https://www.w3schools.com/php/php_ref_filesystem.asp)
- [PHP FileSystem Oficial](https://www.php.net/manual/es/book.filesystem.php)
- [README Guidelines Example](https://gist.github.com/PurpleBooth/109311bb0361f32d87a2)
Files affected by Christian
- index.php
- layouts/modalEditFile.php
- layouts/table.php
- assets/js/init.js
- assets/js/events.js
57 changes: 57 additions & 0 deletions actions/createDirectory/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

session_start();

require_once("../../config.php");
require_once(ROOT . "/modules/validation.php");
require_once(ROOT . "/modules/session.php");
require_once(ROOT . "/utils/joinPath.php");

$errorList = [];
$successList = [];

if (!isset($_POST["dirname"])) array_push($errorList, "Folder name not specified.");
if (!isset($_POST["destpath"])) array_push($errorList, "Destination path not specified.");

if (!count($errorList)) {
$dirname = htmlentities(trim($_POST["dirname"]));
$destpath = htmlentities(trim($_POST["destpath"]));

if (!validateName($dirname)) array_push($errorList, "Folder name is invalid.");
if (!validatePath($destpath)) array_push($errorList, "Destination path is invalid.");
}

if (!count($errorList)) {
try {
$destpath = joinPath([ROOT_DIRECTORY, $destpath]);
$fullpath = joinPath([$destpath, $_POST["dirname"]]);

// Checks if folder already exists
if (file_exists($fullpath)) {
throw new Exception("Directory already exists.");
}

// Checks if destination does not exist
if (!file_exists($destpath)) {
throw new Exception("Parent directory does not exist.");
}

// Checks if destination is not a directory
if (!is_dir($destpath)) {
throw new Exception("Parent item is not a directory.");
}

mkdir($fullpath);
chmod($fullpath, 0777);

array_push($successList, "Directory has been created.");
} catch (Throwable $e) {
array_push($errorList, $e->getMessage());
}
}

setSessionValue("errorList", $errorList);
setSessionValue("successList", $successList);

$url = getSessionValue("path");
header("Location: ../../index.php?path=$url");
58 changes: 58 additions & 0 deletions actions/createFile/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

session_start();

require_once("../../config.php");
require_once(ROOT . "/modules/validation.php");
require_once(ROOT . "/modules/session.php");
require_once(ROOT . "/utils/joinPath.php");

$errorList = [];
$successList = [];

if (!isset($_POST["filename"])) array_push($errorList, "File name not specified.");
if (!isset($_POST["destpath"])) array_push($errorList, "Destination path not specified.");

if (!count($errorList)) {
$filename = htmlentities(trim($_POST["filename"]));
$destpath = htmlentities(trim($_POST["destpath"]));

if (!validateName($filename)) array_push($errorList, "File name is invalid.");
if (!validatePath($destpath)) array_push($errorList, "Destination path is invalid.");
}

if (!count($errorList)) {
try {
$destpath = joinPath([ROOT_DIRECTORY, $destpath]);
$fullpath = joinPath([$destpath, $filename . ".txt"]);

// Checks if file already exists
if (file_exists($fullpath)) {
throw new Exception("File already exists.");
}

// Checks if destination does not exist
if (!file_exists($destpath)) {
throw new Exception("Parent directory does not exist.");
}

// Checks if destination is not a directory
if (!is_dir($destpath)) {
throw new Exception("Parent item is not a directory.");
}

$file = fopen($fullpath, "w");
chmod($fullpath, 0777);
fclose($file);

array_push($successList, "File has been created.");
} catch (Throwable $e) {
array_push($errorList, $e->getMessage());
}
}

setSessionValue("errorList", $errorList);
setSessionValue("successList", $successList);

$url = getSessionValue("path");
header("Location: ../../index.php?path=$url");
39 changes: 39 additions & 0 deletions actions/delete/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

session_start();

require_once("../../config.php");
require_once(ROOT . "/modules/validation.php");
require_once(ROOT . "/modules/session.php");
require_once(ROOT . "/utils/joinPath.php");
require_once(ROOT . "/utils/deleteNode.php");

$errorList = [];
$successList = [];

try {
// Checks if param 'path' exists.
if (!isset($_POST["path"])) throw new Exception("Resource path not specified.");

$path = htmlentities(trim($_POST["path"]));

// Checks if param 'path' is valid.
if (!validatePath($path)) throw new Exception("Resource path is invalid.");

$fullpath = joinPath([ROOT_DIRECTORY, $path]);

// Checks if the resource already exists.
if (!file_exists($fullpath)) throw new Exception("The resource doesn't exist.");

deleteNode($path);

array_push($successList, "The resource has been deleted.");
} catch (Throwable $e) {
array_push($successList, $e->getMessage());
}

setSessionValue("errorList", $errorList);
setSessionValue("successList", $successList);

$url = getSessionValue("path");
header("Location: ../../index.php?path=$url");
15 changes: 15 additions & 0 deletions actions/editFile/get.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php


$_POST = json_decode(file_get_contents('php://input'), true);

$filePath = $_POST['filePath'];
$linesFile = file("../../drive".$filePath);

$data = '';

foreach($linesFile as $line) {
$data .= $line;
}

echo json_encode($data);
5 changes: 5 additions & 0 deletions actions/editFile/put.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

$_POST = json_decode(file_get_contents('php://input'), true);

echo json_encode(file_put_contents("../../drive".$_POST['filePath'], $_POST['data']));
27 changes: 27 additions & 0 deletions actions/renameFile/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

session_start();

# Verify this file is called from POST request
$action = isset($_POST) && isset($_POST['action']) ? $_POST['action'] : null;

require_once('../../config.php');
require_once(ROOT . "modules/session.php");

/**
* Rename File. We can use rename() method.
* It takes oldname or olddir & newname or new dir
* Can be use it to move files between folders
*/
$rootPath = ROOT . "drive";
$location = $_POST['userLocation'];

if ($action) {
$currentPath = $rootPath . $_POST['currentPath'];
$newPath = $rootPath . $_POST['newPath'];
rename($currentPath, $newPath);
}

$url = getSessionValue("path");
header("Location: ../../index.php?path=$url");
exit;
16 changes: 16 additions & 0 deletions actions/searchFile/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

session_start();

require_once("../../config.php");
require_once(ROOT . "/modules/validation.php");
require_once(ROOT . "/modules/session.php");
require_once(ROOT . "/utils/joinPath.php");
require_once(ROOT . "/utils/searchInDrive.php");

// look for the input given by forM GET and search in the whole drive folder with scandir

$_SESSION["search"]= $_GET ["search"];
searchItem();

header ("Location: ../../index.php") ;
Loading