Code:
<?php
$max_size = 15; //Your maximum file size(in mb);
$direc_copy = "uploads/"; //Directory to copy to
//Seperate with a comma
$accepted_file_list = "video,image"; // the files types you will allow to be copied, Possible options are:
//text,image,audio,video,application
$accepted_file_list = explode(",",$accepted_file_list);
$max_size = (($max_size * 1024) * 1024);
$submit = $_POST['submit']; // get the submit
if (isset($submit)){
$filename = $_FILES['file_upload']; //get the file details
$mime_type = explode("/", $filename['type']); //get the first bit of the mime type
if (($filename['size'] > 0) and ($filename['size'] < $max_size)){ //check if a file actually exists.
if (in_array($mime_type[0], $accepted_file_list)){//check if the file is in the accepted_file_list array
copy($filename['tmp_name'], $direc_copy . $filename['name']); // copy the file
$message = "Your file has been uploaded."; //message if copied
}
else {
$message = "Filetype not supported"; //message if filetype not supported
}
} else {
$message = "File is outside of the allowed boundaries";
}
}
?>
<html>
<head>
</head>
<body>
<form action="uploader_test.php" method="post" enctype="multipart/form-data" name="fileuploader" id="fileuploader">
<input type="file" name="file_upload" id="file_upload">
<input type="submit" name="submit" value="submit">
</form>
<?php echo($message . "<br>" . "The link is " . $direc_copy . $filename['name']); ?>
</body>
</html>
HTH

Leave a comment: