<!DOCTYPE html> <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-2"></div> <div class="col-md-8 well"> <h3 class="text-primary">PHP - Simple Copy File By Dragging</h3> <hr style="border-top:1px dotted #ccc;"/> <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#form_modal"><span class="glyphicon glyphicon-plus"></span> Add file</button> <br /><br /> <div class="col-md-5"> <h4>File 1</h3> <div class="table-responsive"> <table class="table table-bordered"> <thead class="alert-info"> <tr> <th>Filename</th> <th>Action</th> </tr> </thead> <tbody> <?php $count=0; foreach ($files as $file){ if($file != '.' && $file !='..'){ ?> <tr> <td> <?php ?> <label><?php echo $file?></label> <?php }else{ ?> <label draggable="true" id="<?php echo $file?>" ondragstart="drag(event);"><?php echo $file?></label> <?php } ?> </td> <td> <?php ?> <center>Copied</center> <?php } ?> </td> </tr> <?php } } ?> </tbody> </table> </div> </div> <div class="col-md-2" style="border:5px solid #ccc; padding:10px;"> <img src="images/copy.png" width="100%" ondrop="drop(event)" ondragover="dragOver(event)"/> </div> <div class="col-md-5"> <h4>File 2</h3> <div class="table-responsive"> <table class="table table-bordered"> <thead class="alert-info"> <tr> <th>Filename</th> </tr> </thead> <tbody> <?php foreach ($files as $file){ if($file != '.' && $file !='..'){ ?> <tr> <td><?php echo $file?></td> </tr> <?php } } ?> </tbody> </table> </div> </div> </div> <div class="modal fade" id="form_modal" tabindex="-1" role="dialog" aria-hidden="true"> <div class="modal-dialog" role="document"> <form action="save_file.php" method="POST" enctype="multipart/form-data"> <div class="modal-content"> <div class="modal-body"> <div class="col-md-3"></div> <div class="col-md-6"> <form method="POST" action=""> <div class="form-group"> <label>File:</label> <input type="file" name="file" class="form-control" required="required"/> </div> </form> </div> </div> <div style="clear:both;"></div> <div class="modal-footer"> <button type="button" class="btn btn-danger" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span> Close</button> <button name="save" class="btn btn-primary"><span class="glyphicon glyphicon-save"></span> Save</button> </div> </div> </form> </div> </div> </body> <script src="js/jquery-3.2.1.min.js"></script> <script src="js/bootstrap.js"></script> <script src="js/script.js"></script> </html>
<?php $filename = $_FILES['file']['name']; $filesize = $_FILES['file']['size']; $filetemp = $_FILES['file']['tmp_name']; if($filesize > 500000){ echo "<script>alert('File too large to upload')</script>"; echo "<script>window.location = 'index.php'</script>"; }else{ $location = "file1/".$newFile; echo "<script>alert('File Saved!')</script>"; echo "<script>window.location = 'index.php'</script>"; } }else{ echo "<script>alert('Only images allowed')</script>"; echo "<script>window.location = 'index.php'</script>"; } } } ?>
<?php $file = "file1/".$_REQUEST['file']; $newfile = "file2/".$_REQUEST['file']; echo "<script>alert('Failed to copy ".$file."')</script>"; echo "<script>window.location = 'index.php'</script>"; }else{ echo "<script>alert('Copied!')</script>"; echo "<script>window.location = 'index.php'</script>"; } } ?>
function dragOver(e){ e.preventDefault(); } function drop(e){ e.preventDefault(); var data = e.dataTransfer.getData("data"); window.location = "copy_file.php?file="+data; } function drag(e){ e.dataTransfer.setData("data", e.target.id); }
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.