<!DOCTYPE> <html lang="en"> <head> <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/> <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/> </head> <body> <nav class="navbar navbar-default"> <div class="container-fluid"> <a class="navbar-brand" href="https://sourcecodester.com">Sourcecodester</a> </div> </nav> <div class="col-md-3"></div> <div class="col-md-6 well"> <h3 class="text-primary">Get File Extension Using PHP Source Code</h3> <hr style="border-top:1px dotted #ccc;"/> <div class="col-md-4"> <form action="save_file.php" method="POST" enctype="multipart/form-data"> <div class="form-group"> <label>Filename</label> <input type="file" name="file" class="form-control" required="required"/> </div> <center><button name="save" class="btn btn-primary"><span class="glyphicon glyphicon-save"></span> Save</button></center> </form> </div> <div class="col-md-8"> <form method="POST" action=""> <button name="get" class="btn btn-primary"><span class="glyphicon glyphicon-arrow-down"></span> Get Extension</button> </form> <br /><br /> <div class="table-responsive"> <table class="table table-bordered"> <thead class="alert-info"> <tr> <td>Filename</td> <td>File Extension</td> </tr> </thead> <tbody> <?php include 'get_ex.php'?> </tbody> </table> </div> </div> </div> </body> </html>
<?php $filename = $_FILES['file']['name']; $filetype = $_FILES['file']['type']; $filetemp = $_FILES['file']['tmp_name']; $filesize = $_FILES['file']['size']; if($filesize > 500000){ echo "<script>alert('File too large to upload')</script>"; echo "<script>window.location = 'index.php'</script>"; }else{ $location ="file/".$filename; echo "<script>alert('File uploaded')</script>"; echo "<script>window.location = 'index.php'</script>"; } } } ?>
<?php foreach ($files as $value) { if ($value != '.' && $value != '..'){ ?> <tr> <td><?php echo $value?></td> <td></td> </tr> <?php } } }else{ foreach ($files as $value) { if ($value != '.' && $value != '..'){ ?> <tr> <td><?php echo $file[0]?></td> <td><?php echo $end?></td> </tr> <?php } } } ?>