473,770 Members | 1,995 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

readfile() and redirection

[PHP]
class DownloadGenerat or {

var $fullFilePath;

function DownloadGenerat or($fullFilePat h) {
$this->fullFilePath = $fullFilePath;
}

function &generateForceD ownloadHeaders( $fullFilePath = '') { //
STATIC VOID METHOD
$file = ($this->fullFilePath ) ? $this->fullFilePath : $fullFilePath;
if (if_file($file) ) {
$filesize = @filesize($file );
header("Content-Disposition: attachment; filename=$file" );
header('Content-Type: application/octet-stream');
header('Content-Type: application/force-download');
header('Content-Type: application/download');
header('Content-Transfer-Encoding: binary');
header('Pragma: no-cache');
header('Expires : 0');
@set_time_limit (600);
readfile($file) ;
}
}

}
[/PHP]

I am trying to "have my cake and eat it too", so to speak. I want to
do a forced download of a file using readfile() and manipulating the
headers; but at the exact same time I need to redirect to another
page, the page that says "hey everything is cool" success message and
display the rest of the application.

Right now what it does is that it does force a download (in Mozilla)
but your window is blank. The user has no ability to navigate any
further and is forced to close and re-open their browser and start all
over again, definitely not an option.

How can I use readfile() to force a download of a file, yet at the
same time display a screen indicating the rest of the application?

The idea I thought up was this:
[PHP]
foreach ($_REQUEST as $key => $val) if (!isset(${$key} )) ${$key} =
$val; // RETRIEVE ALL PASSED VARS

if ($forceDownload ) { // HANDLE FORCED DOWNLOAD
$dlGen =& new DownloadGenerat or($fullFilePat h);
$dlGen->generateForceD ownloadHeaders( );
echo "<a href=\"index.ph p" . $dlGen->generateQueryS tring() .
"\">Continu e</a>\n";
$dlGen = null;
}
[/PHP]

This resulting from
index.php?force Download=1&full FilePath=/tmp/images/blah.jpg
Thanx
Phil
Jul 17 '05 #1
3 8741
> I am trying to "have my cake and eat it too", so to speak. I want to
do a forced download of a file using readfile() and manipulating the
headers; but at the exact same time I need to redirect to another
page, the page that says "hey everything is cool" success message and
display the rest of the application.


Easy. Use an invisible frame to initiate the download.
Jul 17 '05 #2
"Chung Leong" <ch***********@ hotmail.com> wrote in message news:<K8******* *************@c omcast.com>...
I am trying to "have my cake and eat it too", so to speak. I want to
do a forced download of a file using readfile() and manipulating the
headers; but at the exact same time I need to redirect to another
page, the page that says "hey everything is cool" success message and
display the rest of the application.


Easy. Use an invisible frame to initiate the download.


I'm sorry. Invisible frame? <Iframe>? I don't understand, I don't
follow your logic, I'm sorry.

What I have is that upon resizing the image it will do a header()
redirection to a URL that will have its headers changed using a class
method which allows for your browser window to remain in place while
the download prompt comes up via your browser to download the file.
After file download takes place you're still where you are and files
are managed.

I am interested in your easy solution, as you say, but can't
comprehend it in light of the modular approach I have done with the
application I've done so far. Please do explain "invisible frame" to
me.

Thanx
Phil
Jul 17 '05 #3
"Phil Powell" <so*****@erols. com> wrote in message
news:1c******** *************** ***@posting.goo gle.com...
What I have is that upon resizing the image it will do a header()
redirection to a URL that will have its headers changed using a class
method which allows for your browser window to remain in place while
the download prompt comes up via your browser to download the file.
After file download takes place you're still where you are and files
are managed.


It's very simple really. You want to both redirect to a HTML page and
initiate a download. We're talking two HTTP requests here. And the only way
you can initiate multiple page requests to the server with a single click
(without resorting to Javascript) is through frames.

In the page that you redirect to, stick in something like:

<iframe src="download.p hp?param=someth ing" style="display: none" />

That will bring up a download box if the appropriate headers are set. In the
event of problems, the download script can output Javascript code that
either shows the errors on the parent page
(parent.documen t.getElementsBy Id(...).innerHT ML = '' ...) or redirect the
parent to an error page. An alternate strategy would have the page perform
the resizing, save the result to a temp file, which the download script
would then output and delete.
Jul 17 '05 #4

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

Similar topics

2
16916
by: salsipius | last post by:
Hi all thanks in advance for reading. I am writing a serial port app with the help of many examples and I am not quite clear on how to get the data back from the method call? I have pasted the read method below, it takes a void * as the buffer. I know I need to send something by reference but am unclear on how to do it. What I want it the buffer to be a string that I can use or manipulte. Can anyone help Please? int...
0
3106
by: Mustafa Ahmad Malik | last post by:
Hello, I have wrapped the Win32 pipes function in C#. I have created named pipe with PIPE_WAIT in pipemode parameter like this pipehandle = CreateNamedPipe(_pipeName, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, 4096, 4096,
12
6901
by: ORC | last post by:
Shouldn't 'ReadFile' block when timeouts are specified even when running in overlapped mode or am I wrong ??? Thanks Ole
3
3248
by: Shawn August | last post by:
Hello: I am converting a working VB6 program to C#. During testing of the C# version, I noticed the ReadFile API is crashing. The parameters going into the this function are identical to the working VB6 version. I have tried changing the returned buffer datatype from string to object. The program does not crash (no work) if I remove the ref argument on the 2nd argument within the ReadFile API ('psBuffer'). A quick API sniffer revealed:...
2
5735
by: Schorschi | last post by:
Can't seemd to get ReadFile API to work! Returns invalid handle error? =========================================================================== Ok, the visual basic gurus, help! The following is a diskette class (vb .net) that works find, in that I can validate a diskette is mounted, dismount it, lock it, unlock it, get diskette geometry, etc., all with a valid handle from CreateFile API! I can even position the file pointer,...
1
9448
by: Jørn Dahl-Stamnes | last post by:
I'm trying to replace <IMG SRC="some image"> with the usage of readfile, but without luck. I have seen examples like this: header ('Content-length: ' .filesize($image_file)); header ('Content-type: image/jpeg'); readfile ($image_file); This works OK unless you have modified the header before. What I like to do is to display the image *within* HTML codes, something like:
4
13992
by: Eric Renken | last post by:
I am trying to do an Overlapped ReadFile on a HID device and it just isn't working for me. The WaitForSingleObject keeps giving me an error "The system cannot find the file specified." This code need to work in 64bit and 32bit, so I am using IntPtr for pointers instead of int. Here is the structure of OVERLAPPED public struct OVERLAPPED
1
2121
by: mkarja | last post by:
Hi, I have a windows MDI program that draws some shapes that can be saved into a file and read from that file. The save seems to work with the WriteFile function, but for some reason the ReadFile function fails. These WriteFile/ReadFile are win32 api functions. I'll post both, the read and write function codes here so you can take
15
5944
by: Ketchup | last post by:
Hello everyone, I have been stuck with this problem for quite some time now. I am working in VB.NET, using framework 1.0. I have to keep the compatibility down to the original .NET framework as much as possible. I am forced to use API calls for several functions, one of which is ReadFile. The reason is because the framework seems to use ANSI versions of all API functions, limiting the MAX_PATH for filenames to about 260 chars for ...
0
9618
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
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
10259
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
10101
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
10038
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
9906
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6710
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
5354
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
2849
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.