I’m building a script that will save an image from the web to the user’s computer. This is what I’ve learned, so far:
$url = 'http://example.com/my-image.jpg';
$img = '/my/folder/my-image.jpg';
file_put_contents($img, file_get_contents($url));
Is this the right way to do this? If so, how would I get the path to, say, the downloads folder, in the user’s machine?
You can’t. The Downloads folder is a browser-specific location that only the user has control of. The file will download to the folder that is specified by the user.
Use
readfilealong withheaderto force a Save As… dialog to appear.