我正在尝试从站点下载一些文件,但一直遇到问题。首先它正在下载一个空文件,我认为这是因为内容类型,所以有人建议我现在正在做的 application/octet-stream。然后我在实际查找文件时遇到了很多问题。在几个测试用例之后,这是空白问题,然后我对其进行了修改(放入“”),现在我再次下载一个空文件。
基本代码,但希望有人可以提供帮助:
<?php
$filename = $_GET['filename'];
$dir = "training/trainingDocuments/";
$downloadFilename = $dir.$filename;
//ftp://site.com///training/trainingDocuments/8%20-%20SUBSEA%20QUESTIONS__51f034ab37a8e.xls
//$downloadFilename = preg_replace('/\s/', '%', $downloadFilename);
//8 - SUBSEA QUESTIONS__51f034ab37a8e.xls
//if the filename exists
if(is_file($downloadFilename)){
//send the headers
header('Pragma: public'); //FIX IE6 Content-Disposition
header('Content-DEscription: File Transfer');
header('Content-Transder-Encoding: binary');
header(sprintf('Content-Length: %u', filesize($downloadFilename)));
header('Content-type: application/octet-stream');
header("Content-Disposition: attachment; filename=".$downloadFilename."");
}else{
//file doesn't exist
echo "File no exist\n\n";
echo $downloadFilename;
}//end if file exists