File upload and display part of the file php

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:

1.File is uploaded
2.The name of the file is displayed on the main page as a link
3.Once the link is clicked on, information about the file displays (first sentence or so)

The questions I have are:
1. 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

  1. I managed to get the name of the file appear as a link, but I dont know how to display its contents.

Could someone help, please?


 //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'; 

      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"> 



 //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>'; 



          <!--The upload form, second page -->

<form action = "../uploads/" method="POST" enctype="multipart/form-data" >
Название статьи: <br>
<input type = "text" name = "name" value = "text"><br><br>
<input type = "file" name="file"><br><br>
<input id = "add" type = "submit" value="add"><br><br>


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s