$root="D:/wamp/www/新建文件夹/";
if(is_dir($root))
{
$openHandle=opendir($root);
while(false!==($file=readdir($openHandle)))
{
if(!is_dir($root.$file))
{
echo "".$file."
";
echo "$root$file
";
}
}
closedir($openHandle);
}
else
{
echo "文件夹不存在";
}
?>
这段代码为什么不能实现文件下载 浏览器:搜狗浏览器 IE 都试了
回复讨论(解决方案)
用header头下载
用header头下载 能不能给个测试程序啊
已??你?好了
<?php$root="D:/ghost/";if(is_dir($root)){ $openHandle=opendir($root); while(false!==($file=readdir($openHandle))){ if(!is_dir($root.$file)){ echo "<a href='?do=down&file=".$file."&path=".urlencode($root)."'>".$root.$file."</a><br/>"; } } closedir($openHandle);}else{echo "文件夹不存在";}$do=(isset($_REQUEST['do'])) ? addslashes($_REQUEST['do']) : '';if($do=='down') { $file=(isset($_REQUEST['file'])) ? addslashes($_REQUEST['file']) : ''; $path=(isset($_REQUEST['path'])) ? addslashes($_REQUEST['path']) : ''; OB_start(); function DownLoad($info,$file) { OB_Clean(); if(!file_exists($info)) { exit('Error:'.__LINE__.','.basename(__FILE__).'!'); } $info=file_get_contents($info); header('Content-Transfer-Encoding: binary'); header('Content-Type: application/force-download; name="'.$file.'"'); header('Content-Disposition: attachment; filename='.$file.''); header('Cache-control: private'); header('Pragma: no-cache'); header('Expires: 0'); echo $info; die(); } DownLoad($path.$file,$file);}
已??你?好了
<?php$root="D:/ghost/";if(is_dir($root)){ $openHandle=opendir($root); while(false!==($file=readdir($openHandle))){ if(!is_dir($root.$file)){ echo "<a href='?do=down&file=".$file."&path=".urlencode($root)."'>".$root.$file."</a><br/>"; } } closedir($openHandle);}else{echo "文件夹不存在";}$do=(isset($_REQUEST['do'])) ? addslashes($_REQUEST['do']) : '';if($do=='down') { $file=(isset($_REQUEST['file'])) ? addslashes($_REQUEST['file']) : ''; $path=(isset($_REQUEST['path'])) ? addslashes($_REQUEST['path']) : ''; OB_start(); function DownLoad($info,$file) { OB_Clean(); if(!file_exists($info)) { exit('Error:'.__LINE__.','.basename(__FILE__).'!'); } $info=file_get_contents($info); header('Content-Transfer-Encoding: binary'); header('Content-Type: application/force-download; name="'.$file.'"'); header('Content-Disposition: attachment; filename='.$file.''); header('Cache-control: private'); header('Pragma: no-cache'); header('Expires: 0'); echo $info; die(); } DownLoad($path.$file,$file);}不行啊 直接把php文件下下来了
已??你?好了
<?php$root="D:/ghost/";if(is_dir($root)){ $openHandle=opendir($root); while(false!==($file=readdir($openHandle))){ if(!is_dir($root.$file)){ echo "<a href='?do=down&file=".$file."&path=".urlencode($root)."'>".$root.$file."</a><br/>"; } } closedir($openHandle);}else{echo "文件夹不存在";}$do=(isset($_REQUEST['do'])) ? addslashes($_REQUEST['do']) : '';if($do=='down') { $file=(isset($_REQUEST['file'])) ? addslashes($_REQUEST['file']) : ''; $path=(isset($_REQUEST['path'])) ? addslashes($_REQUEST['path']) : ''; OB_start(); function DownLoad($info,$file) { OB_Clean(); if(!file_exists($info)) { exit('Error:'.__LINE__.','.basename(__FILE__).'!'); } $info=file_get_contents($info); header('Content-Transfer-Encoding: binary'); header('Content-Type: application/force-download; name="'.$file.'"'); header('Content-Disposition: attachment; filename='.$file.''); header('Cache-control: private'); header('Pragma: no-cache'); header('Expires: 0'); echo $info; die(); } DownLoad($path.$file,$file);}
错误代码:27
file_put_contents('download/excel.csv',$str);
header("location:download/excel.csv"); //让电脑自动弹出下载对话框
file_put_contents('download/excel.csv',$str);
header("location:download/excel.csv"); //让电脑自动弹出下载对话框 加在哪里啊 怎样加
已??你?好了
<?php$root="D:/ghost/";if(is_dir($root)){ $openHandle=opendir($root); while(false!==($file=readdir($openHandle))){ if(!is_dir($root.$file)){ echo "<a href='?do=down&file=".$file."&path=".urlencode($root)."'>".$root.$file."</a><br/>"; } } closedir($openHandle);}else{echo "文件夹不存在";}$do=(isset($_REQUEST['do'])) ? addslashes($_REQUEST['do']) : '';if($do=='down') { $file=(isset($_REQUEST['file'])) ? addslashes($_REQUEST['file']) : ''; $path=(isset($_REQUEST['path'])) ? addslashes($_REQUEST['path']) : ''; OB_start(); function DownLoad($info,$file) { OB_Clean(); if(!file_exists($info)) { exit('Error:'.__LINE__.','.basename(__FILE__).'!'); } $info=file_get_contents($info); header('Content-Transfer-Encoding: binary'); header('Content-Type: application/force-download; name="'.$file.'"'); header('Content-Disposition: attachment; filename='.$file.''); header('Cache-control: private'); header('Pragma: no-cache'); header('Expires: 0'); echo $info; die(); } DownLoad($path.$file,$file);}
if($do=='down')这个判断始终没有成功 后面大括号内代码没机会执行 怎么办啊
已??你?好了
<?php$root="D:/ghost/";if(is_dir($root)){ $openHandle=opendir($root); while(false!==($file=readdir($openHandle))){ if(!is_dir($root.$file)){ echo "<a href='?do=down&file=".$file."&path=".urlencode($root)."'>".$root.$file."</a><br/>"; } } closedir($openHandle);}else{echo "文件夹不存在";}$do=(isset($_REQUEST['do'])) ? addslashes($_REQUEST['do']) : '';if($do=='down') { $file=(isset($_REQUEST['file'])) ? addslashes($_REQUEST['file']) : ''; $path=(isset($_REQUEST['path'])) ? addslashes($_REQUEST['path']) : ''; OB_start(); function DownLoad($info,$file) { OB_Clean(); if(!file_exists($info)) { exit('Error:'.__LINE__.','.basename(__FILE__).'!'); } $info=file_get_contents($info); header('Content-Transfer-Encoding: binary'); header('Content-Type: application/force-download; name="'.$file.'"'); header('Content-Disposition: attachment; filename='.$file.''); header('Cache-control: private'); header('Pragma: no-cache'); header('Expires: 0'); echo $info; die(); } DownLoad($path.$file,$file);}
你这条语句是不是有问题啊 “echo "".$root.$file."
";” 该怎么改啊
href='?do 改成 href='a.php?do
a.php就是你自己的那?php文件的文件名
已??你?好了
<?php$root="D:/ghost/";if(is_dir($root)){ $openHandle=opendir($root); while(false!==($file=readdir($openHandle))){ if(!is_dir($root.$file)){ echo "<a href='?do=down&file=".$file."&path=".urlencode($root)."'>".$root.$file."</a><br/>"; } } closedir($openHandle);}else{echo "文件夹不存在";}$do=(isset($_REQUEST['do'])) ? addslashes($_REQUEST['do']) : '';if($do=='down') { $file=(isset($_REQUEST['file'])) ? addslashes($_REQUEST['file']) : ''; $path=(isset($_REQUEST['path'])) ? addslashes($_REQUEST['path']) : ''; OB_start(); function DownLoad($info,$file) { OB_Clean(); if(!file_exists($info)) { exit('Error:'.__LINE__.','.basename(__FILE__).'!'); } $info=file_get_contents($info); header('Content-Transfer-Encoding: binary'); header('Content-Type: application/force-download; name="'.$file.'"'); header('Content-Disposition: attachment; filename='.$file.''); header('Cache-control: private'); header('Pragma: no-cache'); header('Expires: 0'); echo $info; die(); } DownLoad($path.$file,$file);}
错误代码:27 ??描述是啥?????出??你看一下
已??你?好了
<?php$root="D:/ghost/";if(is_dir($root)){ $openHandle=opendir($root); while(false!==($file=readdir($openHandle))){ if(!is_dir($root.$file)){ echo "<a href='?do=down&file=".$file."&path=".urlencode($root)."'>".$root.$file."</a><br/>"; } } closedir($openHandle);}else{echo "文件夹不存在";}$do=(isset($_REQUEST['do'])) ? addslashes($_REQUEST['do']) : '';if($do=='down') { $file=(isset($_REQUEST['file'])) ? addslashes($_REQUEST['file']) : ''; $path=(isset($_REQUEST['path'])) ? addslashes($_REQUEST['path']) : ''; OB_start(); function DownLoad($info,$file) { OB_Clean(); if(!file_exists($info)) { exit('Error:'.__LINE__.','.basename(__FILE__).'!'); } $info=file_get_contents($info); header('Content-Transfer-Encoding: binary'); header('Content-Type: application/force-download; name="'.$file.'"'); header('Content-Disposition: attachment; filename='.$file.''); header('Cache-control: private'); header('Pragma: no-cache'); header('Expires: 0'); echo $info; die(); } DownLoad($path.$file,$file);}不行啊 直接把php文件下下来了
我?的??方式不分文件?型皆可下?,只要?文件有?取?限就能被下?,所以你在列出要下?的文件的?候要排除掉php?型.
我的文件名叫 download.php 改了也还是不行 你帮我看看吧
$root="D:/wamp/www/panjinli/downloadsouce";
if(is_dir($root))
{
$openHandle=opendir($root);
while(false!==($file=readdir($openHandle)))
{
if(!is_dir($root.$file))
{
echo "".$root.$file."
";
}
}
closedir($openHandle);
}else
{
echo "文件夹不存在";
}
$do=(isset($_REQUEST['do'])) ? addslashes($_REQUEST['do']) : '';
if($do=='down')
{
$file=(isset($_REQUEST['file'])) ? addslashes($_REQUEST['file']) : '';
$path=(isset($_REQUEST['path'])) ? addslashes($_REQUEST['path']) : '';
OB_start();
function DownLoad($info,$file)
{
OB_Clean();
if(!file_exists($info))
{
exit('Error:'.__LINE__.','.basename(__FILE__).'!');
}
$info=file_get_contents($info);
header('Content-Transfer-Encoding: binary');
header('Content-Type: application/force-download; name="'.$file.'"');
header('Content-Disposition: attachment; filename='.$file.'');
header('Cache-control: private');
header('Pragma: no-cache');
header('Expires: 0');
echo $info;
die();
}
DownLoad($path.$file,$file);
}
?>
已??你?好了
<?php$root="D:/ghost/";if(is_dir($root)){ $openHandle=opendir($root); while(false!==($file=readdir($openHandle))){ if(!is_dir($root.$file)){ echo "<a href='?do=down&file=".$file."&path=".urlencode($root)."'>".$root.$file."</a><br/>"; } } closedir($openHandle);}else{echo "文件夹不存在";}$do=(isset($_REQUEST['do'])) ? addslashes($_REQUEST['do']) : '';if($do=='down') { $file=(isset($_REQUEST['file'])) ? addslashes($_REQUEST['file']) : ''; $path=(isset($_REQUEST['path'])) ? addslashes($_REQUEST['path']) : ''; OB_start(); function DownLoad($info,$file) { OB_Clean(); if(!file_exists($info)) { exit('Error:'.__LINE__.','.basename(__FILE__).'!'); } $info=file_get_contents($info); header('Content-Transfer-Encoding: binary'); header('Content-Type: application/force-download; name="'.$file.'"'); header('Content-Disposition: attachment; filename='.$file.''); header('Cache-control: private'); header('Pragma: no-cache'); header('Expires: 0'); echo $info; die(); } DownLoad($path.$file,$file);}不行啊 直接把php文件下下来了
我?的??方式不分文件?型皆可下?,只要?文件有?取?限就能被下?,所以你在列出要下?的文件的?候要排除掉php?型.
已??你?好了
<?php$root="D:/ghost/";if(is_dir($root)){ $openHandle=opendir($root); while(false!==($file=readdir($openHandle))){ if(!is_dir($root.$file)){ echo "<a href='?do=down&file=".$file."&path=".urlencode($root)."'>".$root.$file."</a><br/>"; } } closedir($openHandle);}else{echo "文件夹不存在";}$do=(isset($_REQUEST['do'])) ? addslashes($_REQUEST['do']) : '';if($do=='down') { $file=(isset($_REQUEST['file'])) ? addslashes($_REQUEST['file']) : ''; $path=(isset($_REQUEST['path'])) ? addslashes($_REQUEST['path']) : ''; OB_start(); function DownLoad($info,$file) { OB_Clean(); if(!file_exists($info)) { exit('Error:'.__LINE__.','.basename(__FILE__).'!'); } $info=file_get_contents($info); header('Content-Transfer-Encoding: binary'); header('Content-Type: application/force-download; name="'.$file.'"'); header('Content-Disposition: attachment; filename='.$file.''); header('Cache-control: private'); header('Pragma: no-cache'); header('Expires: 0'); echo $info; die(); } DownLoad($path.$file,$file);}不行啊 直接把php文件下下来了
我?的??方式不分文件?型皆可下?,只要?文件有?取?限就能被下?,所以你在列出要下?的文件的?候要排除掉php?型.
你是在LINUX下测的吗 我放在WINDOWS上不能成功执行 放在LINUX下载的文件会被写入一部分乱七八糟的内容 求支援啊
已??你?好了
<?php$root="D:/ghost/";if(is_dir($root)){ $openHandle=opendir($root); while(false!==($file=readdir($openHandle))){ if(!is_dir($root.$file)){ echo "<a href='?do=down&file=".$file."&path=".urlencode($root)."'>".$root.$file."</a><br/>"; } } closedir($openHandle);}else{echo "文件夹不存在";}$do=(isset($_REQUEST['do'])) ? addslashes($_REQUEST['do']) : '';if($do=='down') { $file=(isset($_REQUEST['file'])) ? addslashes($_REQUEST['file']) : ''; $path=(isset($_REQUEST['path'])) ? addslashes($_REQUEST['path']) : ''; OB_start(); function DownLoad($info,$file) { OB_Clean(); if(!file_exists($info)) { exit('Error:'.__LINE__.','.basename(__FILE__).'!'); } $info=file_get_contents($info); header('Content-Transfer-Encoding: binary'); header('Content-Type: application/force-download; name="'.$file.'"'); header('Content-Disposition: attachment; filename='.$file.''); header('Cache-control: private'); header('Pragma: no-cache'); header('Expires: 0'); echo $info; die(); } DownLoad($path.$file,$file);}不行啊 直接把php文件下下来了
我?的??方式不分文件?型皆可下?,只要?文件有?取?限就能被下?,所以你在列出要下?的文件的?候要排除掉php?型.
你是在LINUX下测的吗 我放在WINDOWS上不能成功执行 放在LINUX下载的文件会被写入一部分乱七八糟的内容 求支援啊 我在windows和linux下都???,一切正常

要保護應用免受與會話相關的XSS攻擊,需採取以下措施:1.設置HttpOnly和Secure標誌保護會話cookie。 2.對所有用戶輸入進行輸出編碼。 3.實施內容安全策略(CSP)限制腳本來源。通過這些策略,可以有效防護會話相關的XSS攻擊,確保用戶數據安全。

优化PHP会话性能的方法包括:1.延迟会话启动,2.使用数据库存储会话,3.压缩会话数据,4.管理会话生命周期,5.实现会话共享。这些策略能显著提升应用在高并发环境下的效率。

theSession.gc_maxlifetimesettinginphpdeterminesthelifespanofsessiondata,setInSeconds.1)它'sconfiguredinphp.iniorviaini_set().2)abalanceisesneededeededeedeedeededto toavoidperformance andunununununexpectedLogOgouts.3)

在PHP中,可以使用session_name()函數配置會話名稱。具體步驟如下:1.使用session_name()函數設置會話名稱,例如session_name("my_session")。 2.在設置會話名稱後,調用session_start()啟動會話。配置會話名稱可以避免多應用間的會話數據衝突,並增強安全性,但需注意會話名稱的唯一性、安全性、長度和設置時機。

會話ID應在登錄時、敏感操作前和每30分鐘定期重新生成。 1.登錄時重新生成會話ID可防會話固定攻擊。 2.敏感操作前重新生成提高安全性。 3.定期重新生成降低長期利用風險,但需權衡用戶體驗。

在PHP中設置會話cookie參數可以通過session_set_cookie_params()函數實現。 1)使用該函數設置參數,如過期時間、路徑、域名、安全標誌等;2)調用session_start()使參數生效;3)根據需求動態調整參數,如用戶登錄狀態;4)注意設置secure和httponly標誌以提升安全性。

在PHP中使用會話的主要目的是維護用戶在不同頁面之間的狀態。 1)會話通過session_start()函數啟動,創建唯一會話ID並存儲在用戶cookie中。 2)會話數據保存在服務器上,允許在不同請求間傳遞數據,如登錄狀態和購物車內容。

如何在子域名間共享會話?通過設置通用域名的會話cookie實現。 1.在服務器端設置會話cookie的域為.example.com。 2.選擇合適的會話存儲方式,如內存、數據庫或分佈式緩存。 3.通過cookie傳遞會話ID,服務器根據ID檢索和更新會話數據。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

禪工作室 13.0.1
強大的PHP整合開發環境

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

SublimeText3漢化版
中文版,非常好用