Upload file by URL
Posted: Sun Aug 15, 2010 8:18 am
Hey,
I'm not quite experienced with PHP but I'm keen on learning it.
What I want to do is upload a file from my pc, by url, like this:
http://www.mysite.com/upload.php?id=C:\Upload files\myfile.txt
upload.html
uploader.php
How can I, instead of browsing to a file in the html file, skip that and just enter the filepath in the URL and it'll automatically upload to my server.
I'm not quite experienced with PHP but I'm keen on learning it.
What I want to do is upload a file from my pc, by url, like this:
http://www.mysite.com/upload.php?id=C:\Upload files\myfile.txt
upload.html
Code: Select all
<html>
<body>
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" name="lname" /><br />
<input type="submit" value="Upload File" />
</form>
</body>
</html> Code: Select all
<?php
// Where the file is going to be placed
$target_path = "uploads/";
$id = $_GET['id'];
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>