-1

If I do

$file='http://notmywebsite.com/verybigimage.png';
$newfile='test.png';
copy($file,$newfile);

will my server download http://notmywebsite.com/verybigimage.png?

If yes, how can I make my user download http://notmywebsite.com/verybigimage.png without that my server download it?

octern
  • 4,825
  • 21
  • 38
user1365010
  • 3,185
  • 8
  • 24
  • 43
  • By "make your user download", do you mean bring up a download prompt or just straight up download it onto their computer? – Palladium Jul 27 '12 at 21:01
  • @Palladium Bring up a download prompt. :) – user1365010 Jul 27 '12 at 21:02
  • 1
    Well, according to [this forum](http://forums.devshed.com/php-development-5/prompt-file-download-of-external-file-577269.html) making people download external files is just the same as making them download local ones. So go ahead, knock yourself out, and break a leg. – Palladium Jul 27 '12 at 21:05
  • Uh, do you want to copy the file server side by making the client download it instead of the server? Is that what you are asking? – Mahn Jul 27 '12 at 21:07
  • @Mahn I am not understanding a lot, but I think it's that. – user1365010 Jul 27 '12 at 21:12
  • @user1365010 I answered, let me know if that helps, otherwise please give more detail on what you are trying to achieve. – Mahn Jul 27 '12 at 21:21

1 Answers1

0

It's not possible to have the client (the user) download a file and then copy this file in the server in a seamless way, because these two environments are living in different systems — in order to do this, the client needs to upload the file back to the server after downloading it, which in turn would be a pain for the user and slower than simply letting the server download the file and copying it there, if the ultimate goal is having a copy of the file in the server.

Mahn
  • 16,261
  • 16
  • 62
  • 78
  • My goal is just to make him download a file that is not on my server. – user1365010 Jul 27 '12 at 21:31
  • Ah I see, are you familiar with Javascript? This is a job for client-side code, ie using JS. – Mahn Jul 27 '12 at 21:32
  • I want to put the image in a folder and maybe zip it (Then prompt the download). Is this possible in JS? – user1365010 Jul 27 '12 at 21:35
  • You'll have to copy it first server side to zip it, but yes, it should be possible otherwise. It's too broad though, I can't give you a single line of code that will do it, but look up file uploading/downloading tutorials with PHP+Javascript in google, I'm sure there are a ton. – Mahn Jul 27 '12 at 21:38
  • Then, I won't zip it. But is it possible to make the user download a folder that contains a file not on my server? – user1365010 Jul 27 '12 at 21:41
  • Yeah, it should be possible with JS alone. Check out for instance: http://stackoverflow.com/questions/3749231/download-file-using-javascript-jquery – Mahn Jul 27 '12 at 21:43
  • Yes, downloading it, but putting it in a folder? – user1365010 Jul 27 '12 at 21:48
  • Client side? Nope. Why would you need to do that anyway? – Mahn Jul 27 '12 at 21:51
  • For example, if I want to download all images from https://www.google.com/search?num=10&hl=fr&safe=off&site=imghp&tbm=isch&source=hp&biw=1280&bih=666&q=test&oq=test&gs_l=img.3..0l10.2109.2881.0.3392.4.4.0.0.0.0.316.891.0j2j1j1.4.0...0.0...1ac.sf5YW9pwyko . I would do this script so that I download a folder with all that images. Of course, I don't want to download them on the server and then download it in my computer (double time). – user1365010 Jul 27 '12 at 22:01
  • Hm, I would recommend setting up a local server then, that way you can run php on your pc directly and thus the server where you download and copy the images would effectively be your pc. – Mahn Jul 27 '12 at 22:11
  • Thank you for all! I think I will do it that way, but I would be curious to know how one will have been able to do that. – user1365010 Jul 27 '12 at 22:14