Hi all,
Unfortunately i lost a good friend recently to a injury he aquired during battle in afganistan as we were both disabled veterans and met while taking computer classes together. As he was much much farther into the courses, he had written me a easy “upload file” script for the back end of a site i was working on. Unfortunately he was unable to complete a portion that i threw at him right before he passed.
With this code it is just your basic “upload a file code” to be download by others. What i was looking to have added was once the file was uploaded by admin it would show on the front end near the download button a date ( 9/27/12) of the last upload. Also show on the back end the same date of when the last upload was done. Im not to sure on how hard it would be as myself are at the beginning stages of my courses but he mentioned that he was just taken refresher courses.
So here is my code let me know if there are any questions:
[SIZE=4][COLOR="#FF0000"]<?php
$number_of_uploads = 6;
# Set allowed file types, lowercase without period (.)
$allowed_file_types = array("viv","csv","zip","txt");
# Change the upload_folder path, with trailing slash,
# to your full directory path if neccessary, and set
# permissions (chmod) to 777.
$upload_folder = "uploads/";
# Set maximum file upload size in kilobytes.
$max_size_in_kb = 2000;
# Set 1 to rename files, 0 to keep original file names.
$rename_files = 0;
# END SETTING VARIABLES #################
?>
<div id='main-left'><div id=''><img src="../images/header-trade.jpg" alt="" /></div><br/>
<!--The start of the Admin upload Function-->
<br/>
<div class='news-left2' >
<table width="640px">
<tr>
<td width="213px"><img src="images/downloads.png" alt="" /></td>
<td width=""><?php
function printForm()
{
global $allowed_file_types,$number_of_uploads;
print "<form action=\\"". $_SERVER["PHP_SELF"] ."\\" method=\\"post\\" enctype=\\"multipart/form-data\\">\
<p>";
for($i=0;$i<$number_of_uploads;$i++)
{
print "<input type=\\"file\\" name=\\"file[]\\" /><br />";
}
print "<input type=\\"hidden\\" name=\\"upload\\" value=\\"1\\">\
";
print "<input type=\\"submit\\" value=\\"Upload\\"/></p>\
</form>\
";
}
$fileNAMES = array();
if(isset($_POST['upload']))
{
for($i=0;$i<$number_of_uploads;$i++)
{
if(strlen($_FILES['file']['name'][$i]) > 0)
{
$ext = end(explode(".", $_FILES['file']['name'][$i]));
if($rename_files == 1)
{
$fileNAMES[$i] = time()+rand(0,999999);
}
else
{
$xperiods = str_replace("." . $ext, "", $_FILES['file']['name'][$i]);
$fileNAMES[$i] = str_replace(".", "", $xperiods);
}
if(!in_array(strtolower($ext), $allowed_file_types))
{
print "<p>FAILED: ". $_FILES['file']['name'][$i] ." ERROR: File type not allowed.</p>\
";
}
elseif($_FILES['file']['size'][$i] > ($max_size_in_kb*1024))
{
print "<p>FAILED: ". $_FILES['file']['name'][$i] ." ERROR: File size to large.</p>\
";
}
elseif(file_exists($upload_folder.$fileNAMES[$i] .".". $ext))
{
print "<p>FAILED: ". $fileNAMES[$i] .".". $ext ." ERROR: File already exists.</p>\
";
}
else
{
if(move_uploaded_file($_FILES['file']['tmp_name'][$i], $upload_folder.$fileNAMES[$i] .".". $ext))
{
print "<p>UPLOADED: ". $fileNAMES[$i] .".". $ext ."</p>\
";
}
else
{
print "<p>FAILED: ". $_FILES['file']['name'][$i] ." ERROR: Undetermined.</p>\
";
}
}
}
}
printForm();
}
else
{
printForm();
}
?>[/COLOR][/SIZE]
Thank you for all your help and God Bless you and the USA!!!