Page 1 of 1

Upload Files with table

Posted: Fri Oct 21, 2011 10:12 pm
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

Re: Upload Files with table

Posted: Fri Oct 21, 2011 11:32 pm
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