Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有办法阻止某人执行必须下载的php_Php_File_Upload_Execute - Fatal编程技术网

有没有办法阻止某人执行必须下载的php

有没有办法阻止某人执行必须下载的php,php,file,upload,execute,Php,File,Upload,Execute,我的问题是,如果我有一个文件上传网站,有人托管一个PHP文件,我总是强迫服务器下载它,黑客是否有办法在我的服务器上执行PHP而不是下载它 我的代码: <?php $file = "files/" . $_GET["file"]; if (file_exists($file)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet

我的问题是,如果我有一个文件上传网站,有人托管一个PHP文件,我总是强迫服务器下载它,黑客是否有办法在我的服务器上执行PHP而不是下载它

我的代码:

<?php 
$file = "files/" . $_GET["file"];
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;

确保不将文件保存到文档根目录中。Web服务器不应在此之外执行脚本。请确保将用户文件上载到无法直接访问的文件夹中。但是,您应该在
$\u GET[“file”]
中验证名称。如果该值以
序列开头。
,则他们可以在
文件
目录外下载文件。是的,如果
文件
可通过web访问,则
http://www.example.com/files/file.php
将在服务器上执行。如果他们发送类似于
$GET[“file”]=“../../etc/passwd”的内容
他们可以下载这个关键文件。