Solved

PHP Upload File by URL method

Posted on 2009-04-15
8
1,395 Views
Last Modified: 2012-05-06
Hi all,

I'd like to know, if is possible to upload files by passing the path of the file by URL example:

http://www.mysite.com/uploader.php?filename=C:\FilePath\Filename.ext

Then, the uploader.php do the entire process to upload that file...

Is it possible?

My software generate a error report, with some asm info about the error and some other info about the hardware and etc... then like Windows Reporting Tool does, the user will can send the error to us... the error file is called dbghelper.dat and i want to it by php since it use port 80 and firewall will not block it, like some firewalls is configured to do on SMTP Port, FTP Port :(

Thanks in advance :D
and sorry for bad english :(

Best Regards,
Carlos
0
Comment
Question by:cebasso
  • 2
  • 2
  • 2
8 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
I do not think you can do this -- the $_FILES array needs to be populated for file uploads and it cannot be populated via GET in the URL - it would be a security exposure.
0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
Comment Utility
You cannot copy a file to the server through URL because the file stream could not parsed through the HTTP ... you need to use <FORM>
0
 
LVL 4

Author Comment

by:cebasso
Comment Utility
Humm ok
Anyway, the is a method to to something like that in the Code Snippet.. ?!
By passing the file path by URL, do a submit automatically....
Best Regards!!
Carlos

/* upload.php */
 

<?
 

$POST_URL = "uploaded.php";

$FILENAME = $_GET["filename"];
 

?>
 

<html>

<head>

</head>

<body>
 

<form name="return" action="<? echo $POST_URL?>" method="post" enctype="multipart/form-data"> 

<input type="hidden" name="filename" value="<? echo $FILENAME?>"> 

</form>
 

<script language="JavaScript" type="text/javascript"> 

document.return.submit(); 

</script>
 

</body>

</html>
 
 

/* uploader.php */
 

<?

if (!empty($filename) and is_file($filename)) {

$path="/home/cebasso/public_html/upload/";

$path=$path.$filename;
 

if ((eregi(".gif$", $filename_name)) || (eregi(".jpg$", $filename_name))){

copy($filename, $path);

print "<h1><center>Sucess!</center></h1>";

}

else{

print "<h1><center>Error!</center></h1>";

}

}

?>

Open in new window

0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 36

Expert Comment

by:Loganathan Natarajan
Comment Utility
I don't think so, this will work.. as again, you are not sending the actual file stream ... you are just passing the file location to it..

have you tried this?
0
 
LVL 4

Author Comment

by:cebasso
Comment Utility
yes i tried like below
i put the files upload.php and uploader.php in the Server
on Internet Explorer i called
http://www.mysite.com/upload.php?filename=C:\somepic.gif
but i got just a blank page, because i think my php script is wrong... i dont know PHP Programming well, just a little... smls :))
is that script correct? :D
i thin not :(
:D
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
Comment Utility
@cebasso: There is a difference between uploading a file and reading a file stream.  If you read a file stream from, for example, a PHP script, you will get the generated HTML, not the PHP code.  If that is OK with you, then you might try something like this...

Test it here:
http://www.laprbass.com/RAY_get_file_from_url.php?f=RAY_get_file_from_url.php
http://www.laprbass.com/RAY_get_file_from_url.php?f=http://www.google.com

Best regards, ~Ray
<?php // RAY_get_file_from_url.php

error_reporting(E_ALL);

echo "<pre>";
 

// IF WE HAVE A GET ARGUMENT

if (empty($_GET["f"]))                      die("MISSING URL ARGUMENT 'f='");

if (!$data = file_get_contents($_GET["f"])) die("CANNOT GET {$_GET["f"]}");
 

// SHOW THE FILE WE GOT

echo htmlentities($data);

Open in new window

0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now