-   Programming (
-   -   php readfile http VS https (

blizunt7 04-24-2009 08:41 AM

php readfile http VS https
Hey All,
Doing some force downloading with PHP headers. I have the SAME code on and

I do the following:

    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Length: ' . filesize($file));
    header('Content-Disposition: attachment; filename=' . basename($filename));
    header('Content-Transfer-Encoding: binary');

    if (readfile("$file"))
        include "dbconnect.php";
              ..... CODE to update database .....

        echo "FALSE";

When I am on the non secure site, i get the box to download the file, as well as my sql statements execute properly. When I am over SSL, I get the box to download the file, however the database does NOT issue the queries and updates. The interesting thing is that if I remove the header and readfile statements, over ssl, the database queries execute correctly. Thus I believe the problem is over SSL with readfile ??

Anyone have any thoughts or ideas?

Thanks a bunch!

paulsm4 04-27-2009 01:32 AM

Dunno. The part that *really* surprised me was that it *worked* if you eliminated the header and readfile() statements.

So I guess your next step is to narrow it down to one (header) or the other (readfile).

Please post back what you find!

Thanx in advance .. PSM

blizunt7 04-28-2009 08:35 AM

Hey Paulsm4,
What I have also found is that if I change the ORDER of the code so that the SQL statements execute first, and then i issue the readfile, without checking if(readfile(file)); the SQL statements query properly, and the readfile pushes the file to the browser properly.


        include "dbconnect.php";
              ..... CODE to update database .....



So I believe something to be wrong with readfile over SSL. Maybe not "wrong" but functioning differently than over HTTP.

paulsm4 04-29-2009 12:18 AM

OK, good. So we know the only two variables are:

1. readfile()

So the next step is to throw all the error checking ou can at "readfile()" (starting with a meaningful error#, if any).

Keep us posted!

You might also want to try "is_readable($filename)"...

Here are some good tips on PHP error handling/error debugging:

All times are GMT -5. The time now is 05:13 PM.