Upload Files with table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
AndrosM
Forum Newbie
Posts: 1
Joined: Mon Aug 29, 2011 10:10 am

Upload Files with table

Post by AndrosM »

Hello!!

I really need help with my problem

The idea is this one , One user wants to upload a file a pdf or .doc file, and that file can be displayed in another php page.
where a second user can download the specific file.

---Example----
Name Download
book.pdf yes
book2.doc yes
----------------------
For that I need two php files

first the Upload.php

Code: Select all


<h1>Files</h1>
<form action="viewfiles.php" method="post" enctype="multipart/form-data">
<p><strong>Upload files:</strong><br />
<input type="file" name="file" size="700" id="file"></p>
<p>
<input type="submit" value="Upload" />
</p>

The second: viewfiles.php

Code: Select all


if ($_FILES)
{

$name = $_FILES['file']['name'];

switch($_FILES['file']['type'])	

{

case 'application/pdf': $ext = 'pdf'; break;

case 'application/msword': $ext = 'doc'; break;

default: $ext = ''; break;
}
if ($ext)
{
echo '<table align="center" cellspacing="3" cellpadding="3" width="75%">';
echo "<tr>

  <th>Name</th>
  <th>Download</th>
  </tr>";
$n = "application.$ext";
move_uploaded_file($_FILES['file']['tmp_name'], $n);
echo '<tr>';
foreach ($name as $n){
echo "</tr>";
}
echo '<td align="center">'."$name <a href='$n'>yes</a>" . '</td>'; 
}
else echo "'$name' This file is not a pdf or doc";
}
else echo "File not uploaded";

I have one result:

Array ( [file] => Array ( [name] => book.pdf [type] => [tmp_name] => [error] => 1 [size] => 0 ) )
'book.pdf' is not a pdf or doc.

Can anyone help me to display what I want the table and the download file

thanks
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Upload Files with table

Post by social_experiment »

function.header.php
Have a look at that url for displaying files.

As for the upload script (viewfiles.php); check that the file has indeed been uploaded with is_uploaded_file(). Also search the forum on topics related to the matter as this has been covered quite a few times.

Hth
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply