echo "<center><table width=\"300\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">";
echo "<tr><td align=\"center\"><img src=\"images/title_meetingminsadd.jpg\" /><br /><br /></td></tr></table>";
if (isset($_POST['Submit'])){
$userfile = $_POST['userfile'];
echo $userfile;
{
foreach ($_FILES as $my_uploaded_file)
{
// SKIP OVER EMPTY SPOTS - NOTHING UPLOADED
$error_code = $my_uploaded_file["error"];
if ($error_code == 4) continue;
// SYNTHESIZE THE NEW FILE NAME
$f_type = trim(strtolower(end (explode( '.', basename($my_uploaded_file['name'] )))));
$f_name = trim(strtolower(current(explode( '.', basename($my_uploaded_file['name'] )))));
$length = 35;
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
$string = $f_name;
for ($p = 0; $p < $length; $p++) {
$f_name1 .= $characters[mt_rand(0, strlen($characters))];
}
$my_new_file = $uploads . '/' . $f_name1 .'.'. $f_type;
$my_file = $uploads . '/' . $f_name1 .'.'. $f_type;
// OPTIONAL TEST FOR ALLOWABLE EXTENSIONS
if (!in_array($f_type, $file_exts)) die("<div class=\"maintext\">Sorry, $f_type files not allowed</div>");
// IF THERE ARE ERRORS
if ($error_code != 0)
{
$error_message = $errors[$error_code];
die("<div class=\"maintext\">Sorry, Upload Error Code: $error_code: $error_message</div>");
}
// GET THE FILE SIZE
$file_size = number_format($my_uploaded_file["size"]);
// MOVE THE FILE INTO THE DIRECTORY
// IF THE FILE IS NEW
if (!file_exists($my_new_file))
{
if (move_uploaded_file($my_uploaded_file['tmp_name'], $my_new_file))
{
$upload_success = 1;
}
else
{
$upload_success = -1;
}
// IF THE FILE ALREADY EXISTS
}
else
{
echo "<br/><div class=\"maintext\"><b><i>$my_file</i></b> already exists.</div>\n";
// SHOULD WE OVERWRITE THE FILE? IF NOT
if (empty($_POST["overwrite"]))
{
$upload_success = 0;
// IF WE SHOULD OVERWRITE THE FILE, TRY TO MAKE A BACKUP
}
else
{
$now = date('Y-m-d');
$my_bak = $my_new_file . '.' . $now . '.bak';
if (!copy($my_new_file, $my_bak))
{
echo "<br/><div class=\"maintext\"><b>Attempted Backup Failed!</b></div>\n";
}
if (move_uploaded_file($my_uploaded_file['tmp_name'], $my_new_file))
{
$upload_success = 2;
}
else
{
$upload_success = -1;
}
}
}
// REPORT OUR SUCCESS OR FAILURE
if ($upload_success == 2) { echo "<br/><div class=\"maintext\">It has been overwritten.</div>\n"; }
if ($upload_success == 1) { echo "<br/><div class=\"maintext\">File has been uploaded.</div>\n"; }
if ($upload_success == 0) { echo "<br/><div class=\"maintext\"><b>It was NOT overwritten.</b></div>\n"; }
if ($upload_success < 0) { echo "<br/><div class=\"maintext\"><b>ERROR <i>$my_file</i> NOT SAVED - SEE WARNING FROM move_uploaded_file() COMMAND</b></div>\n"; }
if ($upload_success > 0)
{
echo "<br />";
$filename = $f_name1 .'.'. $f_type;
$_SESSION['filename'] = $filename;
echo "<br /><input type=\"submit\" value=\"Continue to Step 2\" onClick=\"location.href='meeting-minutes-add-step2.php'\"><br /><br />";
echo "<br /><br />";
if (!chmod ($my_new_file, 0755))
{
echo "<br/>chmod(0755) FAILED: fileperms() = ";
echo substr(sprintf('%o', fileperms($my_new_file)), -4);
}
}
// END ITERATOR
}
}
} //end if yes for post
else
{
////////////////////////////////////////////////////////////////
echo "<table width=\"350\" cellpadding=\"2\" cellspacing=\"2\">";
echo "<tr align=\"left\"><td>";
echo "<div class=\"maintexterror\">Only .PDF, .DOC, and .DOCX files can be uploaded.</div><br />";
echo "<div class=\"maintext\">Click the \"Browse\" button to find the file you want to upload. After the file has been selected, click the \"Upload\" button below.</div><br />";
echo "</td></tr></table>";
echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\" enctype=\"multipart/form-data\" name=\"UploadForm\">\n";
?>
<input type="hidden" name="MAX_FILE_SIZE" value="<?=$max_file_size?>" />
<?php
for ($n = 0; $n < $nf; $n++)
{
echo "<input name=\"userfile\" type=\"file\" size=\"40\" /><br/>\n";
}
echo "<br /><br /><input value=\"0\" type=\"hidden\" name=\"overwrite\" /><input type=\"submit\" name=\"Submit\" value=\"Upload File\" />";
?>
</form>
<?php
echo "<br /><br /><div class=\"maintext\"><a onclick=\"parent.parent.location.href='meeting-minutes-management.php';return false;\" href=\"javascript:;\" name=\"propr\">Close Window</a></div></center>";
}
|