Mar 29, 2022 12:50 PM
(This post was last modified: Mar 29, 2022 12:52 PM by blackcoder00.)
Hi hackforums family , my problem is that i want to upload multiple files (php/html/css etc..) and keep my old version of files like github does, like to upload new files and when i want go back to my olds files i find it and i can download it i searched in the forums if there's someone that asked about this topic to help me and i didn't find anything the main idea is that i can upload files (html/css/sql etc..) and when i want to upload new files i can anytime go back and find the old version of files like github exactly
PHP Code
<?php
<form method="POST" action="php/upload.php" enctype="multipart/form-data">
<div class="control-panel">
<label>Project folder name</label>
<input type="text" name="directoryName"><br>
<label>Project name</label>
<input type="text" name="projectName"><br>
<label>Project description</label>
<textarea name="description"></textarea><br>
<span>PUSH PROJECT</span>
<input type="file" name="uploadedFile" />
</div>
<input type="submit" class="uploadBtn button5" name="uploadBtn" value="Push" />
</form>
PHP Code
<?php
session_start();
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "github";
$description = $_POST["description"];
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$user = $_SESSION["username"];
$message = '';
echo "hello";
if (isset($_POST['uploadBtn']) && $_POST['uploadBtn'] == 'Push')
{
if (isset($_FILES['uploadedFile']) && $_FILES['uploadedFile']['error'] === UPLOAD_ERR_OK)
{
// get details of the uploaded file
$fileTmpPath = $_FILES['uploadedFile']['tmp_name'];
$fileName = $_FILES['uploadedFile']['name'];
$fileSize = $_FILES['uploadedFile']['size'];
$fileType = $_FILES['uploadedFile']['type'];
$fileNameCmps = explode(".", $fileName);
$fileExtension = strtolower(end($fileNameCmps));
// sanitize file-name
$newFileName = (date("Y-m-d")."_".time()."_". $fileName) . '.' . $fileExtension;
// check if file has one of the following extensions
$allowedfileExtensions = array('jpg', 'php', 'html', 'zip', 'txt', 'xls', 'doc');
if (in_array($fileExtension, $allowedfileExtensions))
{
// directory in which the uploaded file will be moved
$dirc = $_POST["directoryName"];
mkdir($dirc);
$uploadFileDir = './'.$dirc.'/';
$dest_path = $uploadFileDir . $newFileName;
$projectName=$_POST["projectName"];
$sql = "INSERT INTO project
VALUES ('$user', '$dest_path','$description','$projectName')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
if(move_uploaded_file($fileTmpPath, $dest_path))
{
$message ='File is successfully uploaded.';
}
else
{
$message = 'There was some error moving the file to upload directory. Please make sure the upload directory is writable by web server.';
}
}
else
{
$message = 'Upload failed. Allowed file types: ' . implode(',', $allowedfileExtensions);
}
}
else
{
$message = 'There is some error in the file upload. Please check the following error.<br>';
$message .= 'Error:' . $_FILES['uploadedFile']['error'];
}
}
$_SESSION['message'] = $message;
//begin *********************************************************************
header("Location: ../");
Writeln('Give me a Target >');
![[Image: giphy.gif]](https://media.giphy.com/media/1n6CecAWjqgaa0fv0K/giphy.gif)


![[Image: fpZ5a5g.png]](https://i.imgur.com/fpZ5a5g.png)
![[Image: ChZqDxU.gif]](https://i.imgur.com/ChZqDxU.gif)
