Well, the upload now works, but when I choose to view the files I have uploaded, it says that the document is corrupt or cannot be opened.
This error occurs on Microsoft Word and excel files and also Acrobat files (.pdf).
Does anyone know why this could be?
Here is my code:
<?php
if(!$submit)
{
echo("<form enctype=\"multipart/form-data\" action=\"upload.php\" method=\"post\">");
echo("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">");
echo("<tr>");
echo("<td width=\"200\" colspan=\"2\"><font>Upload a file</font></td>");
echo("</tr>");
echo("<tr>");
echo("<td width=\"100\" valign=\"top\"><font>Select File:</font></td>");
echo("<td width=\"100\" valign=\"top\"><input name=\"userfile\" type=\"file\" size=\"25\"></td>");
echo("</tr>");
echo("<tr>");
echo("<td width=\"100\" valign=\"top\"><font>Title:</font></td>");
echo("<td width=\"100\" valign=\"top\"><input type=\"text\" name=\"title\"></td>");
echo("</tr>");
echo("<tr>");
echo("<td width=\"100\" valign=\"top\"><font>Synopsis:</font></td>");
echo("<td width=\"100\" valign=\"top\"><textarea name=\"synopsis\" rows=\"5\" cols=\"17\"></textarea></td>");
echo("</tr>");
echo("<tr>");
echo("<td width=\"100\" valign=\"top\"><font>Review Date:</font></td>");
echo("<td width=\"100\" valign=\"top\"><input type=\"text\" name=\"revdate\"></td>");
echo("</tr>");
echo("<tr>");
echo("<td width=\"100\" valign=\"top\"><font>Status:</font></td>");
echo("<td width=\"100\" valign=\"top\"><select name=\"status\"><option value=\"Active\">Active</option><option value=\"Under Review\">Under Review</option></select></td>");
echo("</tr>");
echo("<tr>");
echo("<td width=\"100\" valign=\"top\"><font>Which section is the file under?</font></td>");
echo("<td width=\"100\" valign=\"top\"><select name=\"folder\"><option selected>Please Select...</option>");
include("connection.php");
// Grab all folder names searching on section eg corsupser for Corporate Support Services
$query = "select * from policyfolders order by folder asc";
$returned = mysql_query($query, $connection);
$rows = mysql_num_rows($returned);
if($rows == 0)
{
}
else
{
for($int=0;$int<$rows;$int++)
{
$array = mysql_fetch_array($returned);
$directory = $array[0];
//$directory = str_replace(" ", "", $directory);
echo("<option value=\"$directory\">$array[0]</option>");
}
}
echo("</select></td>");
echo("</tr>");
echo("<tr>");
echo("<td width=\"200\" valign=\"top\" colspan=\"2\" align=\"center\"><input type=\"submit\" name=\"submit\" Value=\"Upload\"></td>");
echo("</tr>");
echo("</table>");
echo("</form>");
}
else
{
$folder = strtolower($folder);
$folder = str_replace(" ", "", $folder);
$uploaddir = "/usr/local/www/departments/policies/newsite/uploads/" . $folder;
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir . "/" . $_FILES['userfile']['name']))
{
echo("<font><b>Thank you for uploading $the_file_name. It is now available to view <a href=\"policies.php\">here</a></b></font>");
$query = "select * from policyfolders where folder='$folder'";
$returned = mysql_query($query, $connection);
$array = mysql_fetch_array($returned);
$section = $array[1];
$query = "insert into policynew values('" . $_FILES['userfile']['name'] . "', '$title', '$revdate', '$status', '$folder', '$section','$synopsis')";
mysql_query($query, $connection);
}
else
{
print "Possible file upload attack! Here's some debugging info:\n";
print_r($_FILES);
print "<br><br>" . $_FILES['userfile']['error'];
}
}
?>
Many thanks,
Nathan