是否可以即时创建 file.txt 下载它?
该文件应该存储在其中,backup/process/_pro_links_date.txt
但是当我下载该文件时,它没有 .txt
扩展名,并且存储在我的文件夹中。
HTML
<a href="?down=load">File</a>
PHP
if ( $_GET['down'] == 'load' ) {
$date = date( 'Y-m-d H:i:s' );
$myFile = "backup/process/_pro_links_$date.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "Title - Url - Live Date - Process Date \r";
fwrite($fh, $stringData);
$sql = mysql_query("SELECT * FROM k_addlinks WHERE user_code = '".$_SESSION['user_code']."' ") or die (mysql_error());
while ($row = mysql_fetch_array($sql)){
$dated = date("m/j/y g:i",strtotime( $row["date"] ));
if($row["spider_date"] == 'never'){
$sdate = $row["spider_date"];
}else{
$sdate = date("m/j/y g:i",strtotime( $row["spider_date"] ));
}
$stringData = $row['pro_name'] . $row['customDomain'] . $dated . $sdate . '\r';
}
fwrite($fh, $stringData);
fclose($fh);
$path = "backup/process/_pro_links_$date.txt";
$name = "_pro_links_$date.txt";
header("Content-Type: text/plain");
header("Content-Length: " . filesize($path));
header('Content-Disposition: attachment; filename='.$name);
readfile($path);
}
我的代码有什么问题?