PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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
<?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!";
}
?>
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 sure you can see how that sort of thing would be a major security concern, right? It's not possible. If you find a way to do it in any browser, then you have discovered a severe bug (and some browser venders offer cash rewards for finding sever bugs)
I'm afraid that the problem we have here is that the browser will not allow access to a user's filesystem without using a system file dialog (i.e., the window that pops up asking which file to open). That is not the browser's code, but rather it is a the operating systems own code. And the browser simply will not bypass that. To put it a different way, it is required that the user interact with a system file dialog before a file can be accessed by the browser.
Sorry, but kudos for trying to figure out a different angle for a solution to the problem.