Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Sep 2009
    Posts
    48
    Thanks
    1
    Thanked 1 Time in 1 Post

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

    PHP Code:
    $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

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,047
    Thanks
    2
    Thanked 316 Times in 308 Posts
    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.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    New Coder
    Join Date
    Sep 2009
    Posts
    48
    Thanks
    1
    Thanked 1 Time in 1 Post
    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

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,047
    Thanks
    2
    Thanked 316 Times in 308 Posts
    Quote Originally Posted by CFMaBiSmAd View Post
    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.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #5
    New Coder
    Join Date
    Sep 2009
    Posts
    48
    Thanks
    1
    Thanked 1 Time in 1 Post
    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

    Code:
    %%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
    PHP Code:
    <?
    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

    PHP Code:
    <?
    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
    Last edited by Angelous; 10-10-2009 at 06:02 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •