Uploading files to the system is sometimes necessary to access it easily later on. Facebook allows uploading of files such as images, videos or any files on their system. This allows facebook users to view and share it with others and be connected with one another connected with one another.
In archiving system, uploading of documents is integral to it. So, proper storage should be given much attention for easy filtering and searching of documents in the database.
I want to share with you another simple php script that allows single file upload. I got this one from my previous project with this functionality. This one is with the use of bootstrap technology, php and MySQLi. If you want multiple upload script, just look for “Multiple File Uploads” from my post in this blog.
SAMPLE OUTPUT for FILE UPLOAD USING PHP
HTML FILE UPLOAD FORM
<form class="form-horizontal" method="post" action="pages/upload.php" enctype='multipart/form-data'>
<div class="form-group">
<label class="control-label col-lg-1" for="files">Picture</label>
<div class="col-lg-12">
<input type="file" class="form-control" id="files" name="files" required>
</div>
</div>
<div class="modal-footer">
<button type="submit" name="upload" class="btn btn-primary">Upload</button>
<button type="button" class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
</div>
</form>
PHP CODE FILE UPLOAD
<?php
include('../dist/includes/dbcon.php');
$name = $_FILES["files"]["name"];
$type = $_FILES["files"]["type"];
$size = $_FILES["files"]["size"];
$temp = $_FILES["files"]["tmp_name"];
$error = $_FILES["files"]["error"];
if ($error > 0){
die("Error uploading file! Code $error.");
}
else{
if($size > 100000000000) //conditions for the file
{
die("Format is not allowed or file size is too big!");
}
else
{
move_uploaded_file($temp, "../dist/uploads/".$name);
}
}
mysqli_query($con,"INSERT INTO upload(file) VALUES('$name')")or die(mysqli_error());
echo "<script type='text/javascript'>alert('Successfully added new file!');</script>";
echo "<script>document.location='../index.php'</script>";
?>
No comments:
Post a Comment