I am creating an Excel file dynamically(data coming from database). on calling the URL it works fine it shows the download dialog box. but i want to save this file in a folder(i.e in my servers harddisk) dynamically whenever i call this URL using CURl function. How can i set the headers in such a way that it will create the Excel file and save it in a folder. The header code that i am using,
<?php
$name = "myFile";
$file_ending = "xls";
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename开发者_StackOverflow中文版={$name}.{$file_ending}");
header("Pragma: no-cache");
header("Expires: 0");
echo "the data...";
?>
or is there any other method to do so. NOTE-I want it this way because, this function will be called by the web servers scheduler.
You cannot save something in some specific path by setting headers. HTTP headers specifically only help transport data across an HTTP network connection, which knows nothing of file systems.
Perhaps you just want to write the data into a file instead?
file_put_contents('file.xls', "the data...");
Its easy
Create an empty directory, lets say call it "downloads"
create an .htaccess file in the "downloads" directory with the following
Options +SymLinksIfOwnerMatch
IndexIgnore */*
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . dummy.php
Create a file in the "downloads" directory called dummy.php
<?php
param = $_Get["param"];
echo "The file contents, echo anything you want"
?>
By keeping the directory empty, every time it can't find the file, it calls dummy.php
Any file you want the user to download, point them to /downloads/any_madeup_filename
精彩评论