I am so stuck, could someone help, please? I've been learning PHP for a while and currently, I am creating a file upload form.
What needs to happen is this:
- File is uploaded
- The name of the file is displayed on the main page as a link
- Once the link is clicked on, information about the file displays (first sentence or so)
The questions I have are:
- File directory. I am supposed to create a folder, let's say called "uploads" - that's where the files are going to be downloaded to and have my form+php inside that folder, correct? - noob question, I know
- I managed to get the name of the file appears as a link, but I don't know how to display its contents.
Could someone help, please?
Code: https://pastebin.com/rfUgKzSu
//file upload on main page
if (isset($_POST['name'])) {
move_uploaded_file($_FILES['file']['tmp_name'],'add_article_form.php' . $_POST['name'] . '.txt');
echo 'file ' . $_POST['name'] . '.txt' . 'uploaded';
}else{
echo 'There has been a mistake';
}
echo '<br>' ;
echo '<br>' ;
//form on main page
<form action = "add_article_form.php" method = "POST">
<input id = "add" type = "submit" value="add">
</form>
<?php
//display file name
$resource = opendir('../uploads/');
while(($entry = readdir($resource))!== FALSE)
{
if($entry != '.' && $entry != '..'){
echo "<a href = \"#\">$entry</a>" . '<br>';
} else {
"<a href = \"#\">$entry</a>" . '<br>';
}
}
PAGE 2
<!--The upload form, second page -->
<form action = "../uploads/" method="POST" enctype="multipart/form-data" >
Название статьи: <br>
<input type = "text" name = "name" value = "text"><br><br>
Файл:<br>
<input type = "file" name="file"><br><br>
<input id = "add" type = "submit" value="add"><br><br>
</form>