Code: Select all
$todaysDate = date("m_j_Y_"); // Todays date mm_dd_yyyy_
I then append the date to the file name.
Code: Select all
$newfile = $todaysDate.$name;
Moderators: egami, macek, gesf
Code: Select all
$todaysDate = date("m_j_Y_"); // Todays date mm_dd_yyyy_
Code: Select all
$newfile = $todaysDate.$name;
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<title>Uploading files</title>
</head>
<body>
<h1>Uploading files</h1>
<hr><!-- Makes a Horizontal line accross the page-->
<!-- Upload Form -->
<form action='upload.php' method='post' enctype='multipart/form-data'>
File: <input type='file' name='upload'>
<input type='submit' name='submit' value='Upload File Now'>
</form>
</body>
</html>
Code: Select all
<?php
if($_POST['submit']){
// Assign uploaded file information to Variables
$name = $_FILES['upload']['name'];
$temp = $_FILES['upload']['tmp_name'];
$type = $_FILES['upload']['type'];
$size = $_FILES['upload']['size'];
// Validate variables echo "$name<br />$temp<br />$type<br />$size";
// File types allowed to be uploaded
if(($type == 'application/pdf') || ($type == 'application/msword') || ($type == 'application/vnd.openxmlformats-officedocument.wordprocessingml.document') || ($type == 'application/vnd.ms-excel') || ($type == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') || ($type == 'image/jpg') || ($type == 'image/jpeg')){
//Limit file size to 30mb $size is the max file size alloud.
if($size <= 31457280){
// echo "The file: $name size is $size";
$todaysDate = date("m_j_Y_"); // Todays date mm_dd_yyyy_
//add the date to the begining of the file name.
$newfile = $todaysDate.$name;
// echo $newfile;
move_uploaded_file($temp,"documents/$newfile");
// echo "<img src='$newfile'>";
$link = "<a href='documents/$newfile'>$newfile</a>"; //Places the upload as a link into a variable
echo $link;
}else{
echo "The file: $name is to big....<br />The size is $size and need to be less than 30mb";
}
}else{
echo "This type $type is not allowed";
}
}else{
header("Location: index.html");
}
?>