...

View Full Version : readfile() PHP Download issue - files are always downloading as 'corrupt'- Any Help?



Angelous
10-10-2009, 05:55 AM
$prodlink = $_POST['prodcode'];
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=giftcertificate.jpg");
readfile("/path/to/$prodlink.jpg");




That is the download prompt code I have.

I need the file name to be defined by what they put in the form input box on the previous page.

That product code they input becomes $prodlink which inturn would be the name of the .JPG they would download.

...............

Essentially a walkthrough of what should happen :

They enter their information on the form on the previous page - including the
Product Code

They Click Submit

Information is added to Database

Download Prompt comes up with $prodlink.jpg (where $prodlink is the product code and also the name of the jpg in the downloads file)



Alex

CFMaBiSmAd
10-10-2009, 06:15 AM
When you open the downloaded file using a programming editor, what is in it. Also, what size is the downloaded file compared to the size of the original file?

We cannot really tell you what is wrong until you investigate exactly what is being downloaded.

Angelous
10-10-2009, 06:29 AM
Original size is 22Kb

The downloaded size is 2Kb and it is just an image.

The whole purpose of this is that I am selling a service on my website. Its to do with wills and inheritence etc.

When they buy membership to my site - they recieve a certificate of their chosen theme.

Each certificate has a product number which they enter in the registration form.

When they register.

The form adds their info to the database - and prompts them the download.



The product code is used as $prodlink

since the name of the file - is also the product code...



But its not working right

Angelous

CFMaBiSmAd
10-10-2009, 06:47 AM
When you open the downloaded file using a programming editor, what is in it.

If you aren't, can't, or won't investigate what is actually being downloaded, you will never solve your problem because we don't know what you are getting until you look and tell us.

Except for the two pieces of information about the sizes, all the rest of that is irrelevant.

Angelous
10-10-2009, 07:00 AM
Oh sorry - just I am very tired I have been at this all day - trying to figure it out and by all day I mean over 15 hours. Not this specific issue - just working on the site.


The contents of that downloaded file is


%%HEADER%%
That Username/E-Mail is already registered!


Which is supposed to be the error message if they try to register the same email twice or username twice...

: /



This is the Form

<?
include "MyLastRequest.dat";
ob_start();

?>

%%HEADER%%



<?php
include("conf.inc.php"); // Includes the db and form info.
if (!isset($_POST['submit'])) { // If the form has not been submitted.
echo "<form action=\"complete.php\" method=\"POST\">";
echo "<table>";
echo "<br><br><br>";
echo "<tr>";
echo "<td colspan=\"2\"><h2>Register Your Details</td>";
echo "</tr>";
echo "<br><br><br>";
echo "<tr>";
echo "<td width=\"50%\">Username:</td><td width=\"50%\"><input name=\"username\" size=\"18\" type=\"text\" />";
echo "</tr>";
echo "<tr>";
echo "<td width=\"50%\">Password:</td><td width=\"50%\"><input name=\"password\" size=\"18\" type=\"text\" />";
echo "</tr>";
echo "<tr>";
echo "<td width=\"50%\">Email:</td><td width=\"50%\"><input name=\"email\" size=\"18\" type=\"text\" />";
echo "</tr>";
echo "<tr>";
echo "<td width=\"50%\">Product Code:</td><td width=\"50%\"><input name=\"prodcode\" size=\"18\" type=\"text\" />";
echo "</tr>";
echo "<tr>";
echo "<td colspan=\"2\"><input type=\"submit\" name=\"submit\" value=\"submit\"</td>";
echo "</tr>";
echo "</table>";
echo "</form>";
} else { // The form has been submitted.





$username = form($_POST['username']);
$password = md5($_POST['password']); // Encrypts the password.
$email = form($_POST['email']);
if (($username == "") || ($password == "") || ($email == "")) { // Checks for blanks.
exit("There was a field missing, please correct the form.");
}
$q = mysql_query("SELECT * FROM members WHERE username = '$username' OR email = '$email'") or die (mysql_error()); // mySQL Query
$r = mysql_num_rows($q); // Checks to see if anything is in the db.
if ($r > 0) { // If there are users with the same username/email.
exit("That Username/E-Mail is already registered!");
} else {
mysql_query("INSERT INTO members (username,password,email) VALUES ('$username','$password','$email')") or die (mysql_error()); // Inserts the user.

header("Location: download.php");

}
mysql_close($db_connect); // Closes the connection.
?>


%%FOOTER%%

<?

$template = ob_get_contents();
ob_end_clean();


include "includes/Header.inc.php";
include "includes/Footer.inc.php";
include "includes/StandardReplacements.inc.php";

echo $template;
?>



This is the download.php


<?
include "MyLastRequest.dat";
include("conf.inc.php"); // Includes the db and form info.
ob_start();
?>


%%HEADER%%


<?
echo "<br><br><br><br><br>";
echo "<h2>You Download of your Gift Certificate will begin shortly...</h2>";
echo "<br><br><br><br>";
echo "If you Download has not started within 30 seconds; Please try downloading<br>";
echo "by clicking <a href='http://www.mylastrequest.ie/downloads/$prodcode.zip'>Here</a>.";
echo "<br><br><br><br><br>If you continue to have issues please <a href='contact.php'>Contact Us</a> quoting your<br>";
echo " invoice details as you received them in your E-Mail";





$prodlink = $_POST['prodcode'];
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=$prodcode.zip");
readfile("/path/to/$prodcode.zip");




?>
%%FOOTER%%

<?

$template = ob_get_contents();
ob_end_clean();

include "includes/Header.inc.php";
include "includes/Footer.inc.php";
include "includes/StandardReplacements.inc.php";

echo $template;
?>
Angelous



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum