Link to home
Start Free TrialLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

Why is this zip file empty?

I've got a link that looks like this: http://loosecannonfitness.com/downloads.php?email=bruce@brucegust.com

It hits that page and, provided it gets appropriately validated, it hits this code:

$michelle_row=mysqli_fetch_assoc($michelle_query);
	$vivian="update hammons set download_success='Y' where email='$michelle_row[email]'";
	$vivian_query=mysqli_query($cxn, $vivian);
	if($michelle_row['workout']=="1775")
	{
		$filename="1775.zip";
	}
	else
	{
		$filename="Devildog.zip";
	}
	header("Content-Type: application/zip");
	header('Content-Disposition: attachment; filename='.$filename);

Open in new window


The "update" part works great and I get the box that asks if I want to save or open the zip file. The problem is, although I can look at my server and see the "1775.zip" file that's over 22MB, when I go to download it, it's 0 bytes.

In other words, everything seems to be in place except for the content of the file.

What am I doing wrong?
SOLUTION
Avatar of skullnobrains
skullnobrains

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bruce Gust

ASKER

First of all, I think your "skullnobrains" is both hilarious in that it's an obvious misnomer.

Secondly, there are two questions I have:

If the whole of my script looks like this:

<?php
include("carter.inc"); 
$cxn = mysqli_connect($host,$user,$password,$database)
or die ("couldn't connect to server");
$michelle="select * from hammons where email='$_GET[email]' and download_success<>'Y'";
$michelle_query=mysqli_query($cxn, $michelle);
if(!$michelle_query)
{
	$rats=mysqli_errnor($cxn).': '.mysqli_error($cxn);
	die($rats);
}
$michelle_count=mysqli_num_rows($michelle_query);
if(!$michelle_count>0)
{
	header("location:downloads_fail.php");
	exit();
}
else
{
	$michelle_row=mysqli_fetch_assoc($michelle_query);
	$vivian="update hammons set download_success='Y' where email='$michelle_row[email]'";
	$vivian_query=mysqli_query($cxn, $vivian);
	if($michelle_row['workout']=="1775")
	{
		$filename="1775.zip";
	}
	else
	{
		$filename="Devildog.zip";
	}
	header("Content-Type: application/zip");
	header('Content-Disposition: attachment; filename='.$filename);
}
?>

Open in new window


Where does your suggestion belong?

Second question: I'm not familiar fpassthru. I went out to the manual (http://php.net/manual/en/function.fpassthru.php) and found this:  

Reads to EOF on the given file pointer from the current position and writes the results to the output buffer.

Could you put that in layman's terms and explain to me what that means?

I appreciate you, friend! Glad you're up and running on a Saturday!
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you!
Avatar of skullnobrains
skullnobrains

It sends the file line-by-line as if it were browser output, written with echo.

ray:

not quite. it acts the same as readfile (which is simpler btw, thanks @insoft for making it one line shorter) or stream copy to stream would act.

they copy the file block by block. the file is moved as fast as the disk and network can handle. the read side is mmapped and the write side is sent to the php output buffer which itself if flushed asynchronously to the webserver's / the system's buffers. in real life, on what i assume to be a lamp server, the file is mmapped by increments of 2 4k blocks at a time and flushed to apache's buffer ( which is large enough to handle the whole file in this case ). this is world's appart more efficient that reading line by line when it comes to zip files.