Created
April 6, 2018 10:24
-
-
Save anikseu/a0e2aa64d7850adaa9895a195da6a7b9 to your computer and use it in GitHub Desktop.
Copy a File from remote server to local server just by submitting a URL.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <title>CopyFileFromURL script</title> | |
| <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> | |
| <div class="container" style="margin-top:50px;" > | |
| <div class="row"> | |
| <div class="col-sm"> | |
| </div> | |
| <div class="col-sm"> | |
| <form action="script.php" method="post"> | |
| <div class="form-group"> | |
| <label for="exampleInputEmail1">Source URL</label> | |
| <input type="text" name="sourceURL" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter source URL"> | |
| <small id="emailHelp" class="form-text text-muted">Example: http://greatwebsusa.com/fileName.zip</small> | |
| </div> | |
| <div class="form-group"> | |
| <label for="exampleInputPassword1">File Name</label> | |
| <input type="text" name="fileName" class="form-control" id="exampleInputPassword1" placeholder="Enter new File name"> | |
| <small id="emailHelp" class="form-text text-muted">Example: newFile.zip</small> | |
| </div> | |
| <input type="submit" class="btn btn-primary" value="Submit"> | |
| </form> | |
| <?php | |
| //storing data | |
| $fileName = $_POST['fileName']; | |
| $file = $_POST['sourceURL']; | |
| $newfile = $_SERVER['DOCUMENT_ROOT'] . "/". $fileName; | |
| echo '<div class="alert alert-primary" role="alert">'; | |
| //start the copy | |
| if ( copy($file, $newfile) ) { | |
| echo "Copy success! <br/><br/>Copied From: ".$file."<br/><br/>Saved at: ".$newfile; | |
| //success! | |
| }else{ | |
| echo "Fill the form correctly!!"; | |
| //first run or fail! | |
| } | |
| echo '</div>'; | |
| ?> | |
| </div> | |
| <div class="col-sm"> | |
| </div> | |
| </div> | |
| </div> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment