473,778 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how can i make a download through php

i have a dinamically generated file! and i have a button on my page...
i want to download the file by ajax when i click the button! i tried
to send the headers in the xhtmlrequest but my browser does not pop up
that dialog box to download the file!!

thank you!!!
Apr 1 '08 #1
3 1710
domnulnopcea schreef:
i have a dinamically generated file! and i have a button on my page...
i want to download the file by ajax when i click the button! i tried
to send the headers in the xhtmlrequest but my browser does not pop up
that dialog box to download the file!!

thank you!!!
Show some code!!
Apr 1 '08 #2
domnulnopcea wrote:
i have a dinamically generated file! and i have a button on my page...
i want to download the file by ajax when i click the button! i tried
to send the headers in the xhtmlrequest but my browser does not pop up
that dialog box to download the file!!

thank you!!!
Include in your page a URL that points to a php program with a parameter
to identify the file you want to generate, and make a php programm to
send it.

In my code I have this:

<A HREF="filesend. php?id=437">cli ck to download</A>

That invokes the filesned.php program and requests file id 437 in this
instance.

The guts of filesend.php are these.

$name, $content are the 'name' and the actual content of a file.
get_mime() is a function that uses my linux list of extenstion->mime
type mappings to set up a mime type.
Filesend.php the main features..
==============
<?php
//omitted from here is a load of SQL preamble that
//gets the file name and content from an SQL database
//according to the GET id=437 sent to this program
$mtype=get_mime ($name);
//spit out standard header stuff
header("Pragma: public");
header("Expires : 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: ".$mtype);
header("Content-Disposition: attachment; filename=\"".$n ame."\"");
header("Content-Transfer-Encoding: binary");
print $content;
?>
// be careful to leave no blank line after closing PHP
MIME_LIB.php
============
<?php
// looks up mime type in /etc/mime.types and returns the type, or a
default if unmatched
// makes no attempt to interrogate the file content as such.
// THIS NEEDS MORE WORK!!! it doesn't get all types..espciall y DWG/DXF!!
// Mind you we don't want to inmvoke plug-ins for these..
function get_mime($filen ame)
{
$default="appli cation/force-download";
// first extract the extension
$array=explode( ".",$filena me); // split the name into the bits
separated by periods
$count=count($a rray);
if ($count<2) // if there IS NO extension..
return $default; // and let the user sort it out.
$ext=$array[$count-1]; // it will be the last element in the array..
$fp=fopen("/etc/mime.types", "r");
if(!$fp) return ($default); // no /etc/mime.types file
while (!feof($fp))
{
$buffer = fgets($fp, 128);
if (ctype_space($b uffer{0}) || $buffer{0}=='#' || $buffer{0}=='\n ')
continue; // skip empty lines. or lines starting with spaces
or hashes
sscanf($buffer, "%s %s %s %s %s %s \n",$mime_type, $extension,
$extension1, $extension2, $extension3, $extension4);
if ($ext==$extensi on || $ext==$extensio n1 || $ext==$extensio n2 ||
$ext==$extensio n3 || $ext==$extensio n4 )
{
fclose ($fp);
return($mime_ty pe);
}
}
fclose($fp);
return $default;
}
?>
=========

Hope this is of use.
Apr 1 '08 #3
On 1 Apr, 10:33, domnulnopcea <domnulnop...@g mail.comwrote:
i have a dinamically generated file! and i have a button on my page...
i want to download the file by ajax when i click the button! i tried
to send the headers in the xhtmlrequest but my browser does not pop up
that dialog box to download the file!!

thank you!!!
What do you want the AJAX bit to do?
Apr 1 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
8539
by: chon | last post by:
I have an ASP page that is sent a file location as a parameter. It opens this file, loads the ADODB.Stream object and does a binary write to the page forcing the download dialog to appear. This all works fine. If the user selects "Open" or "Cancel", the window closes, which is the desired behavior. If they select "Save", the location dialog shows up, they save the file and the window remains open. I've tried a number of things to get...
0
2584
by: jmd | last post by:
Hello. I want to write a C# program that does completely automatically what, until now, I do manually, witch is describe below : 1. I launch IE (6) 2. I browse to my desired download page, say http://www.site.com/download This download page contains some textboxes, checkboxes, radiobuttons, a DOWNLOAD BUTTON and text 3. I check some checkboxes, select some radiobuttons, enter text in some textboxes and click on the download button
0
1835
by: Buddy Ackerman | last post by:
I am trying to implment a file download via a link such that when clicked, instead of starting the default application for that type of file the user will be presented with a download dialog window. Well, thanks to Steve Orr, I have that working. However, I still have a few issues. First, the download dialog does not have the name of the file being downloaded in the "File name" field, instead it has the name of the aspx page that have...
3
1645
by: Nathan Sokalski | last post by:
I have a webform that contains a button which I want to do three things: 1. Delete a record from a database 2. Let the user download a text file that is generated 3. Refresh the page to show that the record was deleted I am able to do any of these things separately with no trouble. The problem occurs when I try to offer a download AND call my refresh method. When I try to do a download and call my refresh method, only the download is...
18
16407
by: jmd | last post by:
Hello, I posted the following in the C# forum but without one answer. But perhaps now in vb.net someone has some guidelines ! This is my question : I want to write a vb.net program that does completely automatically what, until now, I do manually, witch is describe below : 1. I launch IE (6)
1
3583
by: a.r.austin | last post by:
Hello, I am trying to download a few files one after another from a remote server. Problem is that I don't know how to, or if I am able at all, set a time out for download. I don't want to time out whole script, just a part if file won't download in 2mins then skip to the next one. Previously, I had a Javascript implementation with AJAX, this time I thought of doing it in PHP since PHP has far better array functions, I don't have to do...
16
3258
by: matt | last post by:
I have used some free code for listing files for download, but I want to send an email to the administrator when the file has been downloaded. I have got some code in here that does it, but it will not print in the username or email amddress of the person doing the download - which I am collecting from a form on the previous page. I can get the name and email address to print out normally, just not into the email sending body. I have...
1
2174
by: JayLembeck | last post by:
Over 50,000 Free Ringtone. Get the Latest Ringtone. Download now- Fast, Free and Easy. Get your FREE surprise RINGTONE now! http://seekoutfast.info/free-ringtone/ free ringtone free ringtone new ringtone popular ringtine download ringtone download verizon ringtone download cingular ringtone download mosquito ringtone download mp3 ringtone download nextel ringtone download verizon ringtone download nokia ringtone download midi ringtone mobile...
5
3694
by: Khafancoder | last post by:
Hi guys, i am building a FileSharing website, i wanna allow users to be able using download managers such as DAP to download files from webserver but don't allow them to retrive files url... so i used Response.WriteFile but it won't trigger any download manager such as DAP or FlashGet i used this code :
1
47485
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. I’m going to show you how to do that using a perl script. What You Need Any recent...
0
9464
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10292
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10122
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8954
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7471
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6722
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5368
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2860
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.