获取PHP中的downloads文件夹的路径? [英] Get the path of the downloads folder in PHP?

查看:112
本文介绍了获取PHP中的downloads文件夹的路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个脚本,该脚本会将网络上的图像保存到用户的计算机上。到目前为止,这是我所学到的:

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));

这是正确的方法吗?如果是这样,我将如何获得用户计算机中的 downloads文件夹的路径?

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.

使用 readfile header 强制显示另存为...对话框。

Use readfile along with header to force a Save As... dialog to appear.

<?php
header('Content-disposition: attachment; filename=image.jpg');
header('Content-type: image/jpeg');
readfile('/server/path/to/image.jpg');
?>

这篇关于获取PHP中的downloads文件夹的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆