Direct Server Downloads

August 24th, 2009

Have you ever wanted to copy a file straight from a website to your server? The following PHP script will allow you to enter a URL and download the file straight to your server into the same directory as the PHP file.

<?php

$getFile = $_POST["getFile"];
$fileName = end(explode('/', $getFile));

function showForm($upload) {
echo ("
<a href='./'>Browse Directory</a><br><br>
<form action='$PHP_SELF' method='POST'>
<input name='getFile' type='text'>
<input type='submit' value='$upload'>
</form>
");
}

if(is_null($getFile)) { showForm("Upload"); }
else {
if(@copy($getFile, $fileName.".tmp")) {
echo("<a href='$fileName.tmp'>$fileName</a> uploaded <i>succesfully!</i>");
showForm("Upload Another File");
}
else {
echo("<b><span style='color:red;'>Failed to copy <i>$getFile</i></span></b><br>");
showForm("Try Another File");
}
}

?>
  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.