Upload file by URL

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!

Moderator: General Moderators

Post Reply
vixez
Forum Newbie
Posts: 2
Joined: Sun Aug 15, 2010 8:17 am

Upload file by URL

Post by vixez »

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

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> 
uploader.php

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!";
}

?> 
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.
User avatar
PHPHorizons
Forum Contributor
Posts: 175
Joined: Mon Sep 14, 2009 11:38 pm

Re: Upload file by URL

Post by PHPHorizons »

Hello vixez,

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)

Cheers
vixez
Forum Newbie
Posts: 2
Joined: Sun Aug 15, 2010 8:17 am

Re: Upload file by URL

Post by vixez »

Would ther be a way I can, instead of saving it to the server, load the text file in a textbox?

Then save th contents of the textbox to a file on the server.
User avatar
PHPHorizons
Forum Contributor
Posts: 175
Joined: Mon Sep 14, 2009 11:38 pm

Re: Upload file by URL

Post by PHPHorizons »

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. ;)
Post Reply