PHP - Forced Download Not Working In Ie
I am generating a snapshot of some data and giving the users the ability to download that snapshot. I am trying to serve that file to the users and it works great in Firefox, but the IE users just get a blank file. I'm using the following:
<?php header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Pragma: no-cache'); header('Content-Type: text/plain; charset=ISO-8859-1'); // plain text file $filename = 'C:\WINDOWS\Temp\snapshot.txt'; header("Content-Disposition: attachment; filename=\"".$filename."\";" ); header("Content-Length: ".filesize($filename)); readfile("$filename"); ?> I've changed multiple items several times and each works in FF, but none work in IE. Is anyone aware of any IE specific headers that need to be sent? It's just a plain text file, nothing fancy. Similar TutorialsTo give some background, I'm currently working on a private site that allows members access to large document files via a torrent system. Now, this is the PHP code I have: Code: [Select] $id = $_REQUEST['id']; if (!$id) httperr(); $res = mysql_query("SELECT name FROM torrents WHERE id = $id") or sqlerr(__FILE__, __LINE__); $row = mysql_fetch_assoc($res); $fn = "$torrent_dir/$id.torrent"; if (!$row || !is_file($fn) || !is_readable($fn)) httperr(); $fs = filesize($fn); $tor_fname = $row["filename"]; mysql_query("UPDATE torrents SET hits = hits + 1 WHERE id = $id"); require_once "include/benc.php"; // Torrent Encoding Functions $dict = bdec_file($fn, (1024*1024)); $dict['value']['announce']['value'] = "$DEFAULTBASEURL/announce.php?passkey=$CURUSER[passkey]"; $dict['value']['announce']['string'] = strlen($dict['value']['announce']['value']).":".$dict['value']['announce']['value']; $dict['value']['announce']['strlen'] = strlen($dict['value']['announce']['string']); header("Content-Type: application/x-bittorrent"); header("Content-Disposition: attachment; filename=\"" . basename($tor_fname) . "\"" ); print(benc($dict)); This is taken from (and is the majority of) the file download.php. This is called like: download.php?id=?? The above should work, but when I use it, it tries to save the file as download.torrent, even though the $tor_fname variable doesn't contain that value. I'd obviously like to force the filename to be '<filename>.torrent' rather than the same name as the php script with .torrent on the end. Any ideas? Am I doing something stupid, or is there some way of doing this? I was able to upload the files to the DB but now am trying to retrieve it from the table but it's not working.
my code below
<?php while($row = mysql_fetch_array($query1)) { (list($id, $name) = mysql_fetch_array($query1)); echo"<tr>"; echo"<td> $row[category]</td>"; echo"<td> $row[description]</td>"; echo"<td> $row[amount]</td>"; ?> <td> <a href="approved_req.php?id=<?php echo urlencode($id);?>" ><?php echo urlencode($name);?></a> </td> <?php echo"<td> $row[status]</td>"; ?> <td><a class="btn btn-success" <?php echo" href='invoice.php?id=$row[id]'> Pay </a></td>";?></a> <?php echo"</tr>"; } // } ?> </table> <?php if(isset($_GET['id'])) { // if id is set then get the file with the id from database //$con = mysql_connect('localhost', 'root', '') or die(mysql_error()); //$db = mysql_select_db('test', $con); $id = $_GET['id']; $query = "SELECT name, type, size, content " . "FROM requisition WHERE id = '$id'"; $result = mysql_query($query) or die('Error, query failed'); list($name, $type, $size, $content) = mysql_fetch_array($result); header("Content-length: $size"); header("Content-type: $type"); header("Content-Disposition: attachment; filename=$name"); ob_clean(); flush(); echo $content; mysql_close(); exit; } ?>Thanks in advance Hi, this is my first post:) pretty sure i will be posting here in the future. Anyway i am having trouble with a php script which downloads a file from a mysql database. This php script works for text files and should work for most files from what i understand. When downloading a text file, the whole file is downloaded from the server. When downloading an mp3 file, only 16kb are downloaded and the file does not play. When looking at the data in the database, it displays that the full file is there (correct amount of bytes, so there is nothing wrong with my upload php script). Does anyone have any suggestions as to what I can change to make this work? Code: [Select] <?php if(isset($_GET['id'])) { // if id is set then get the file with the id from database $link=mysql_connect('localhost', 'root', ''); @mysql_select_db('filemgr') or die ("<p>Could not connect to mysql!</p>"); $id = $_GET['id']; $query = "SELECT name, type, size, content " . "FROM upload WHERE id = '$id'"; $result = mysql_query($query) or die('Error, query failed'); list($name, $type, $size, $content) = mysql_fetch_array($result); header("Content-length: $size"); header("Content-type:$type"); header("Content-Disposition: attachment; filename=$name"); echo $content; mysql_close($link); exit; } ?>
Basically I would like to place a link on my website and have the user download a file, but rather than just right clicking and choosing save target as, the link must be clicked, on the next page the file is fetched and then the client can download the file. How would I go about setting this up please? I have made a Php program that downloads an Inno setup installation file for installing a program. However, if I for one or another reason want to make a new download of the same Inno setup installation file, the previous file will still be found in the Download folder. Each of the downloads get a number in parenthesis, setup(1), setup(2), setup(3) etc. However, I wondered if it is posible to erase the previous file in the same process as I download a new one, so that however many downloads I do, there will all the time only be one occurence of this file in the Download folder. The download code is as follows: $exe = "Inno script/Test_setup.exe"; header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"Test_setup.exe\""); header("Content-Length: " . filesize($exe)); readfile($exe); Thanks in advance. Sincerely
Hi,i will like to know how to put a file on my website for people to download..please how should i go about it? thanks merry christmass I've written the following code: Code: [Select] <?php echo '<img src="Sheph.png" />'; function Wad(){ if (file_exists("Sheph.png")) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename("Sheph.png")); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize("Sheph.png")); ob_clean(); flush(); readfile("Sheph.png"); exit; } } Wad(); ?> What I want to do is show the image AND show a file download window. The problem is that it shows the download window but the image doesn't appear. and if I comment the function and keep the echo part only,the image appears normally. What's wrong ? i am trying to let users download images, but it seems to only be working for only a png image. i've tried .txt, word, and mp3. here is my code for getting the path of the file: // get full file path (including subfolders) $file_path = $fileName; find_file(BASE_DIR, $fname, $file_path); if (!is_file($file_path)) { die("File does not exist. Make sure you specified correct file name."); } these other files that i am getting, are in the same folder as the image. the error that i am getting, is "File does not exist. Make sure you specified correct file name." here are the allowed extensions of the files: Code: [Select] $allowed_ext = array ( // archives 'zip' => 'application/zip', // documents 'pdf' => 'application/pdf', 'doc' => 'application/msword', 'xls' => 'application/vnd.ms-excel', 'ppt' => 'application/vnd.ms-powerpoint', // executables 'exe' => 'application/octet-stream', // images 'gif' => 'image/gif', 'png' => 'image/png', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', // audio 'mp3' => 'audio/mpeg', 'wav' => 'audio/x-wav', // video 'mpeg' => 'video/mpeg', 'mpg' => 'video/mpeg', 'mpe' => 'video/mpeg', 'mov' => 'video/quicktime', 'avi' => 'video/x-msvideo' ); I have a small program that is to be used to export data from some MYSQL tables into an Excel spreadsheet. It does the export successfully, the first pass, but each subsequent download selection causes the browser to display the html code as text to the browser. If I disable the excel output, the page redraws successfully un subsequent requests. The header definition I have is ias follows: Code: [Select] $FileInfo = pathinfo(filename); // fix for IE catching or PHP bug issue header("Pragma: public"); header("Expires: 0"); // set expiration time header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); // browser must download file from server instead of cache // force download dialog header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-type: application/x-msexcel"); header("Content-Type: application/download"); // use the Content-Disposition header to supply a recommended filename and // force the browser to display the save dialog. if ($download_filename == "") $download_filename = "download.xlm"; header("Content-Disposition: attachment; filename=".$download_filename.";"); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($filename)); @readfile($filename); I did not setup this header, because to be honest, these things confuse the heck out of me. Can anyone see what may be wrong with this? Can you give me some suggestions? I can post more of the code if needed, but i believe that this is the area of interest for this issue. Thanks in advance. I created this php class which recieves an sql query from flash and then produces a csv file for download. The code in its current form produces a csv file on the server. However, I want it to save on the client computer with a 'Save As' dialog box. I am testing on localhost. Here is the class: <?php class CSVExport { public function __construct() { require_once 'Zend/Date.php'; require_once 'DatabaseConnection.php'; } public function exportCSV($query) { $result = mysql_query($query); $fname = 'CSVFile.csv'; $headers = array(); $rowArray = array(); $numFields = mysql_num_fields($result); for ($i = 0; $i < $numFields; $i++) { $headers[] = mysql_field_name($result , $i); } $fp = fopen($fname, 'w'); if ($fp && $result) { header('Content-Type: application/csv'); header('Content-Disposition: inline; filename='.$fname); fputcsv($fp, $headers); while ($thisrow = mysql_fetch_row($result)) { fputcsv($fp, $thisrow); } readfile($fname); fclose($fp); } die; } } Thanks Little help please? 1. I tried downloading a .txt file on mywebsite but it turned out to be viewing the text file, works on .doc files though 2. Can i have a string variable saved to a file to be downloaded in textfile (.csv) algorith would be like this csv_value = "1,2,3,4,5,6,7,8,9,0"; downloadlink(csv_value,file_name.csv); PS. I used output_buffering = true on my php.ini so i have a little problem if your to suggest to use the header() function. unless there is another loophole. thanks in advance yours truly Art =) Hello, I made that script for previewing all the images in the directory: Code: [Select] $dir = "../images"; $images = glob($dir . "*.jpg"); foreach($images as $image) { echo $image; } Now what i would like to do is to put checkbox to every image. And when i press download button, all the selected images are downloaded. (as .zip, .rar) Thank you very much for your help This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=316412.0 How do I make it so when a user clicks download, it will download the image from the path to their computer? Hi all, I'm trying to make a PHP script that downloads a file off a remote FTP server and serves the file to the visitor with a limited download speed. Right now I'm using fopen() like this: Code: [Select] $path = "ftp://".$username.":".$password."@".$server."/"; $fullPath = ($path.$fileName); $speed = 400; // 400 kb/s download rate header("Cache-control: private"); header("Content-Type: application/octet-stream"); //header("Content-Length: ".filesize($fullPath)); header("Content-Disposition: filename=\"".$fileName."\""); flush(); $fd = fopen($fullPath, "r"); while(!feof($fd)) { echo fread($fd, round($speed*1024)); flush(); sleep(1); } fclose ($fd); The file does download but with the wrong speed (8kb/s), does anyone know why? When I run the same code with a local file instead of a file on FTP it works fine and downloads at the speed I set it to.. Thanks Hello! I'm making a interface in a website do manage files in a ftp hosted on other server. I'm using the function ftp_get() to download a file but I've tried different aways but I dosent seem do be able to download the file directly from the FTP server do the user the only way it works is if I download the file to the website server first then to the client. Is there any way that I can download the file directly to the user without have to hosting it permanently on the website server? Thank you I have the following code, but wish to allow admin members to download the short WMV video without having the page reload. My page can have anything to to 20 videos on the page. I can place a button there but how to I get the video files to download and not play when clicked. Code: [Select] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Admin</title> <link href="style2010.css" rel="stylesheet" type="text/css"> </head> <body style="width:1000px; width: 50%; margin-left: auto; margin-right: auto;"> <div style="width:1000px; padding-right: 3px; padding-left: 3px; height:100%; min-height: 500px;"> <div align="center"><h2>Admin</h2><br /></div> <div style="float: left; padding-left: 5px;"> <form name="delete" method="post" action=""> <div align="center" style="float: left; padding: 0 10px 50px 10px;"> <object classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" id="MediaPlayer1" standby="Loading Windows Media Player components..." width="300" height="300"> <PARAM NAME="url" value="67.wmv" /> <param name="src" value="67.wmv" /> <param name="showcontrols" value="true" /> <param name="autostart" value="false" /> <!--[if !IE]>--> <object type="video/x-ms-wmv" data="67.wmv" width="300" height="300"> <param name="src" value="67.wmv" /> <param name="autostart" value="false" /> <param name="controller" value="true" /> </object> <!--<![endif]--> </object> <br />67.wmv<br />Delete above file? <input name="67---wmv" type="checkbox" value="delete"> </div> <br clear="all"/><input type="submit" name="Delete Selected" value="Delete Selected"> </form> <br /><br /> </div> </div> <br style="clear:both" /> </body> </html> I have music (my own) that I want to put on my website for download, and I was wondering if there is a way to keep track of how many people download each song, by tracking the clicks and displaying that number in a css-styled box. Anyone know how this is done? I don't need help with the css, just the php. How can i create a download page that allows you to download *.php files on your server. Because if you just click on it it sends you to the page but I just want it to download it. Also i want to be able to do that on the .jpeg files. Thanks Jragon i need a php script for download the enire directory with the files . i need a script for that .. ex- floder 11 it contains 23 files ....when user click a button i want to download the floder 11 and inside the floder 11 has to be allow files are included in the folder |