Skip to content

Commit

Permalink
show uploaded files
Browse files Browse the repository at this point in the history
  • Loading branch information
fabalexsie committed May 29, 2024
1 parent b8a0166 commit 2e11c8c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
1 change: 1 addition & 0 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ services:
- "1337:80"
volumes:
- ./uploads:/var/www/html/uploads
- ./index.php:/var/www/html/index.php # this is just for testing purposes
49 changes: 33 additions & 16 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,45 @@
<!DOCTYPE html>
<?php
$msgs = [];
if(!empty($_FILES['uploaded_file']))
{
$path = "/var/www/html/uploads/";
$path = $path . basename( $_FILES['uploaded_file']['name']);

if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $path)) {
$msgs[] = "The file ". basename( $_FILES['uploaded_file']['name']).
" has been uploaded";
} else{
$msgs[] = "There was an error uploading the file, please try again!";
}
}
?><!DOCTYPE html>
<html>
<head>
<title>Upload your files</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form enctype="multipart/form-data" action="index.php" method="POST">
<?php
foreach ($msgs as $msg) {
echo "<p>$msg</p>";
}
?>
<form enctype="multipart/form-data" action="/" method="POST">
<p>Upload your file</p>
<input type="file" name="uploaded_file"></input><br />
<input type="submit" value="Upload"></input>
</form>
<ul>
<?php
$dir = "/var/www/html/uploads/";
$files = scandir($dir);
foreach ($files as $file) {
if ($file == '.' || $file == '..') {
continue;
}
echo "<li><a href='uploads/$file'>$file</a></li>";
}
?>
</ul>
</body>
</html>
<?PHP
if(!empty($_FILES['uploaded_file']))
{
$path = "/var/www/html/uploads/";
$path = $path . basename( $_FILES['uploaded_file']['name']);

if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $path)) {
echo "The file ". basename( $_FILES['uploaded_file']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
}
?>

0 comments on commit 2e11c8c

Please sign in to comment.