PHP Upload File by URL method

Posted on 2009-04-15
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:\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,
Question by:cebasso
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
LVL 110

Expert Comment

by:Ray Paseur
ID: 24147743
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.
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 24147858
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>

Author Comment

ID: 24147916
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!!

/* upload.php */
$POST_URL = "uploaded.php";
$FILENAME = $_GET["filename"];
<form name="return" action="<? echo $POST_URL?>" method="post" enctype="multipart/form-data"> 
<input type="hidden" name="filename" value="<? echo $FILENAME?>"> 
<script language="JavaScript" type="text/javascript"> 
/* uploader.php */
if (!empty($filename) and is_file($filename)) {
if ((eregi(".gif$", $filename_name)) || (eregi(".jpg$", $filename_name))){
copy($filename, $path);
print "<h1><center>Sucess!</center></h1>";
print "<h1><center>Error!</center></h1>";

Open in new window

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 24148020
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?

Author Comment

ID: 24148112
yes i tried like below
i put the files upload.php and uploader.php in the Server
on Internet Explorer i called\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 :(
LVL 110

Accepted Solution

Ray Paseur earned 500 total points
ID: 24153087
@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:

Best regards, ~Ray
<?php // RAY_get_file_from_url.php
echo "<pre>";
if (empty($_GET["f"]))                      die("MISSING URL ARGUMENT 'f='");
if (!$data = file_get_contents($_GET["f"])) die("CANNOT GET {$_GET["f"]}");
echo htmlentities($data);

Open in new window


Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

707 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