English 中文(简体)
PHP - List of Excel files to download from Intranet Site?
原标题:

I have a intranet site running PHP 5 that needs to list a folder containing only Excel files.

Ideally the user needs to be able to input some search criteria (ie date) and the files would be filtered into a list of hyperlinks. These hyperlinks could then be selected to download the excel file.

What I have so far is:

//get search parameters (from a form)
$s_Date = $_GET[ s_Date ];
$s_Shift = $_GET[ s_Shift ];
$s_Name = $_GET[ s_Name ];

//search folder
foreach(glob("c:folderAfolderB*".$s_Date."*".$s_Shift."*".$s_Name."*.*") as     $FileName)
{
    echo basename($FileName);
    echo"<a href=?myad=".basename($FileName)."/>Download</a>"."<br />";
}

This returns list of files but selecting hyperlinks doesn t prompt for download.

How do I get the hyperlink to force a content-type of msexcel?

最佳回答

Assuming you are using a PHP script to deliver the file conent, the script needs to set the Content-Type header:

<?
    header( Content-Type: application/excel );
    header( Content-Disposition: attachment;filename=myfile.xls );
    // send file content
?>

Note you can also set the name to use for the file using the Content-Disposition header.

You might also want to consider a more well-formed <a> tag that points to your download script:

echo  <a href="dl.php?myad=  .urlencode(basename($FileName)).  ">Download</a><br /> ;

In this example, you need to replace dl.php with your actual script.

问题回答

Also append Content-Length header:

header( Content-Length : . filesize( myfile.xls ));

Client would like to know how big file is and how much of it has already been downloaded.





相关问题
How to upload and download file from a server using C#

I am developing a webpage in that the user can download their Resume for Edit. So I have a link to download the article. I use the following code for download. DataTable dt = user.getUserDetails(2); ...

Detecting PDF Download

I have recently added functionality for generating pdf reports to a web application. However the reports can be quite large and take some time to show the pdf download dialog. I want to show a spinner ...

Writing file to users giving sporadic error in IE

I have a very interesting issue with only specific IE implementations. I have an ASPX page that is used to write files down to the user, as part of the process the page uses the following code to ...

PHP - List of Excel files to download from Intranet Site?

I have a intranet site running PHP 5 that needs to list a folder containing only Excel files. Ideally the user needs to be able to input some search criteria (ie date) and the files would be filtered ...

Determine total size of SVN directory/trunk

Is there a way to count/calculate the total size of a svn directory if you were to checkout a revision? I have limited internet downloads so I need to know how big something is before I go and ...

Scala and html: download an image (*.jpg, etc) to Hard drive

I ve got a Scala program that downloads and parses html. I got the links to the image files form the html, Now I need to transfer those images to my hard drive. I m wondering what the best Scala ...

Downloading file with wxHTTP?

Im really stumped. Im using the wxHTTP class in wxWidgets to try and download two files. The first request succeeds but the second one fails when wxHTTP->GetInputStream is called. Between downloads, ...

热门标签