0

I'm wanting to create a website that allows an user to put a link in a field and once the user submits the form, the "image" link added to the field will be remote uploaded to my server (to the path I specified in my server).

A friend of mine did this once, and he told me that he used the file_get_contents() function to get this working, but I cannot figure out how I'd do it.

Any help would be appreciated.

Thanks.

aborted
  • 4,481
  • 14
  • 69
  • 132
  • related: http://stackoverflow.com/questions/3711597/is-it-safe-to-let-the-users-provide-the-link-for-their-image/3711697#3711697 – RobertPitt Mar 18 '11 at 09:45

1 Answers1

1

file_get_contents() will read file contents into a variable.
if you need to copy file to your server, use copy() instead.

copy($_POST['link'],basename($_POST['link']));
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
  • you should note that the location of the link should be url encoded as `%20` / spaces causes issues in PHP 5.2.1 or prior. – RobertPitt Mar 18 '11 at 09:50
  • How about remote uplaoding (copying) multiple files from links? Like getting all links from a textarea, and each of them should be separately uploaded to my server? – aborted Mar 31 '11 at 09:47
  • @Dugi what's so special with it? get your links into array and loop over them – Your Common Sense Mar 31 '11 at 10:59