我正在开发一个php项目。我想自动下载mysql中每个新上传的文件而不点击任何下载链接或按钮。我希望php脚本在mysql中检测新上传的文件并在硬盘上自动下载。
我该怎么做?
答案 0 :(得分:0)
这是从php.net
获取的php上传脚本的示例$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Possible file upload attack!\n";
}
现在回声后你可以回复这个
echo "File is valid, and was successfully uploaded.\n";
//Now here we will force the header to download the file as attachment in browser
return header('Content-Disposition: attachment; filename="'.$uploadfile.'");
上传脚本只是一个基本的例子,我发布它是因为你没有展示你的,我觉得如果你看到它会更好,你可以在这里阅读更多关于标题PHP.NET - Headers