Hy Guys

As i previously mentioned i run a PPD site, but i notice i have a huge error. Every time when the members of my site ready to download a file they get the following message (please see picture)
Picture

I attach here the defailt.php code so you can have a look that line 51. I tried to put the obl start obl flush but its just not work. I checked on the begining its no space or blank line, so i tottaly lost because i dont know what the cause of it. Please help if you can

<?php ob_start(); ?>
<?php

    global $user , $tpl , $db , $c , $page;



    if( $data = $db->row("select f.*,(select count(1) from `download` where `fid`=f.id) as downloads from `file` f where f.global='{$c->global_id}' and f.status=1") and $data['status']==1 ){

        js::$i->put('js/dsession.js','dsession',false);

        page::$i->setTitle( $data['name'] );

        if(!isset($_SESSION['file_session'][$data['id']])){

            $_SESSION['file_session'][$data['id']] = md5( microtime(true) . $_SERVER['REMOTE_ADDR'] );


        }

        $ssFileString = $_SESSION['file_session'][$data['id']].'|'.$data['id'].'|'.$_SERVER['REMOTE_ADDR'];

        // CPALead
        if($data['cpalead']) js::$i->put(('http://www.cpalead.com/show_cu.js?pub=' . config::read('cpalead','pub') . '&subid=' . $ssFileString ),'cpalead_loader',false);
        //-->

        // AdWorkMedia
        if($data['adworkmedia']==1) js::$i->put('http://www.adworkmedia.com/gLoader.php?test=true&GID='.config::read('adworkmedia','gid').'&pubID='.config::read('adworkmedia','pubid').'&sid='. $ssFileString,'adworkmedia_loader',false);
        //-->

        // AdsCendmedia
        if($data['adscendmedia']==1){
            page::$i->head = '<script type="text/javascript">var gwloaded = false;</script>';
            js::$i->put('http://adscendmedia.com/gwjs.php?aff='.config::read('adscendmedia','aff').'&prf='.config::read('adscendmedia','prf').'&sid=' . $_SESSION['file_session'][$data['id']],'adscendmedia',false);
        }


        // AD Gate Media
        //if($data['adgatemedia']==1) js::$i->put('http://gateway.adgatemedia.com/'.config::read('adgatemedia','aff').'-' . config::read('adgatemedia','gtw'),'adgatemedia_loader',false);
        //--> 

            if( $file_session = $db->row("select * from `file_session` where `fid`='{$data['id']}' and `key`='".esc($_SESSION['file_session'][$data['id']])."'") ){
                if($file_session['status']==1){

                    // File type
                    //header('Content-type: MIMETYPE');

                    // Download

                    if(file_exists( $data['file'] )){ 

                        header('Content-Disposition: attachment; filename="'.$data['name'].'"');

                        // Plik do pobrania
                        readfile( $data['file'] ); 

                        die();

                    } else page::setError('Action Success, but file not exists! Contact with administrator');

                }    
            } else $db->insert('file_session',array(
                'fid'=>$data['id'],
                'key'=>$_SESSION['file_session'][$data['id']],
                'crt'=>date("Y-m-d H:i:s"),
                'ip'=>$_SERVER['REMOTE_ADDR'],
                'status'=>0
            ));

    if($data['cpalead']){ 
        $GeneralButton = ("startGateway('".config::read('cpalead','gateway')."');"); 
    } else { 
        if($data['adworkmedia']){ 
            $GeneralButton = ("javascript:gLoad_".config::read('adworkmedia','gid')."(); return false;");
        } else { 
            $GeneralButton = ("javascript:initGateway(); return false;"); 
        } 
    }

        $tpl->assign(array(
            'GeneralButton' => $GeneralButton,
            'data' => $data,
            'file_session' => $_SESSION['file_session'][$data['id']]
        ));
        module::$i->on();

    } else page::$i->val('<div id="header"><div id="header-wrapper"><div class="user-error tac">Sorry<br /><strong style="font-size:20px">File not found!!</strong></div></div></div>');

?>
<?php ob_flush(); ?>
Member Avatar for diafol

WHy are you starting a new thread for the same issue?

I'm assuming that your issue is still with the config.php file. You followed the advice with regard to that file?

sorry i start a new tread because i get the files unecrypted so its much easier to spot the problem. Yes i have double check the config.php aswell and i didnt see any blank line or empty space on the top. But now you can see the header() method here in the default.php, and you can also see i add the obl flash function on the top and bottom, and its still the same error

Its so upsetting. I not belive we cant find a solution for this issue. Awww I paste here both of the codes, please somebody help me, i even dont mind to pay for it...

Config.php

<?php
/**
 * @version 1.0
 */

    class config extends core{
        /**
         * Data Base MySQL
         */
        static $db_host = 'dfhjklj';
        static $db_user = 'fghjkl2';
        static $db_pass = 'Aasdfghj';
        static $db_base = 'dfghjkl';
        static $db_start_query = 'SET NAMES UTF8'; // Not change!

        /**
         * Global
         */
        static $script_name = 'Filemonster.org';
        static $page_dir = ''; // dir of the site (if the side is in the main catalogue of domain leave empty)
        static $with_url = ''; // www. or leave empty


        /**
         * Pagination
         */
        static $str_default_insite = '20'; // Domyślna ilość elementów w stronicowaniu
        static $str_default_anomaly = '5'; // Odchylenie stronicowania (Długość ciągu stron)

        /**
         * Auth
         */
        static $sys_token = 'bd3bc7b5d6c6227045e598558d629a21'; // Zmiana klucza spowoduje błąd w autoryzacji

        /**
         * JavaScript
         */
        static $javascript_map = array(
            // Core JavaScript/Ajax
            'core' => 'js/core.js',

            // jQuery
            'jq' => 'js/jquery.js',
            //'jq-ui' => 'js/jquery-ui-1.7.2.custom.min.js',
            'jq-ui' => 'js/jquery-ui-1.8.16.custom.min.js',

            // "Clouds"
            'jq-tooltip' => 'js/jquery.tooltip.min.js',

            // jQuery-DataPicker - Graficzne wybieranie daty
            'jq-datapicker' => 'js/jquery-ui-1.7.2.datapicker.js',

            // jQuery-LightBox
            'jq-lightbox' => 'js/jquery.colorbox-min.js',

            // CP (Control Panel)
            'cp' => 'js/cp.js',

            // Editor HTML
            'tiny_mce' => 'extra/tinymce/tiny_mce.js'
        );

        /**
         * CSS
         */
        static $css_map = array(
            // General CSS
            'general' => 'css/style.css',
            'ui' => 'css/ui-style.css',
            // CSS Control Panel
            'cp' => 'css/cp.css',
            // Standard CSS and CP
            'simple' => 'css/simple.css',
            // Massages CSS
            'messages' => 'css/messages.css',
            // CSS Internet Explorer
            'browser-ie' => 'css/ie.css',
            // CSS Google Chrome
            'browser-chrome' => 'css/chrome.css',
            // CSS JavaScript/Ajax
            'javascript' => 'css/javascript.css',
            // Pagination
            'pagination' => 'css/pagination.css',

            // jQuery
            'jquery-ui' => 'css/ui-lightness/jquery-ui-1.7.2.custom.css',
            'lightbox' => 'css/lightbox.css'
        );

        static $currency = "$";

/**
 * **********************************************************************************************************
 * Advanced part, Changes aren't being recommended to this Section because it can result in Total stopping the System
 * **********************************************************************************************************
 */

        /**
         * Smarty
         */
        static $tpl_dir = ''; // Smarty

        /**
         * Modules
         */
        static $module_dir = 'module/'; // Moduły
        static $module_default = 'home'; // Domyslny modul
        static $module_default_function = 'default'; // Domyslna funkcja

        /**
         * Admin Panel
         */
        static $admin_dir = 'admin/';
    }



?>

And the default.php

<? ob_start(); ?>
<?php

    global $user , $tpl , $db , $c , $page;



    if( $data = $db->row("select f.*,(select count(1) from `download` where `fid`=f.id) as downloads from `file` f where f.global='{$c->global_id}' and f.status=1") and $data['status']==1 ){

        js::$i->put('js/dsession.js','dsession',false);

        page::$i->setTitle( $data['name'] );

        if(!isset($_SESSION['file_session'][$data['id']])){

            $_SESSION['file_session'][$data['id']] = md5( microtime(true) . $_SERVER['REMOTE_ADDR'] );


        }

        $ssFileString = $_SESSION['file_session'][$data['id']].'|'.$data['id'].'|'.$_SERVER['REMOTE_ADDR'];

        // CPALead
        if($data['cpalead']) js::$i->put(('http://www.cpalead.com/show_cu.js?pub=' . config::read('cpalead','pub') . '&subid=' . $ssFileString ),'cpalead_loader',false);
        //-->

        // AdWorkMedia
        if($data['adworkmedia']==1) js::$i->put('http://www.adworkmedia.com/gLoader.php?test=true&GID='.config::read('adworkmedia','gid').'&pubID='.config::read('adworkmedia','pubid').'&sid='. $ssFileString,'adworkmedia_loader',false);
        //-->

        // AdsCendmedia
        if($data['adscendmedia']==1){
            page::$i->head = '<script type="text/javascript">var gwloaded = false;</script>';
            js::$i->put('http://adscendmedia.com/gwjs.php?aff='.config::read('adscendmedia','aff').'&prf='.config::read('adscendmedia','prf').'&sid=' . $_SESSION['file_session'][$data['id']],'adscendmedia',false);
        }


        // AD Gate Media
        //if($data['adgatemedia']==1) js::$i->put('http://gateway.adgatemedia.com/'.config::read('adgatemedia','aff').'-' . config::read('adgatemedia','gtw'),'adgatemedia_loader',false);
        //--> 

            if( $file_session = $db->row("select * from `file_session` where `fid`='{$data['id']}' and `key`='".esc($_SESSION['file_session'][$data['id']])."'") ){
                if($file_session['status']==1){

                    // File type
                    //header('Content-type: MIMETYPE');

                    // Download

                    if(file_exists( $data['file'] )){ 

                        header('Content-Disposition: attachment; filename="'.$data['name'].'"');

                        // Plik do pobrania
                        readfile( $data['file'] ); 

                        die();

                    } else page::setError('Action Success, but file not exists! Contact with administrator');

                }    
            } else $db->insert('file_session',array(
                'fid'=>$data['id'],
                'key'=>$_SESSION['file_session'][$data['id']],
                'crt'=>date("Y-m-d H:i:s"),
                'ip'=>$_SERVER['REMOTE_ADDR'],
                'status'=>0
            ));

    if($data['cpalead']){ 
        $GeneralButton = ("startGateway('".config::read('cpalead','gateway')."');"); 
    } else { 
        if($data['adworkmedia']){ 
            $GeneralButton = ("javascript:gLoad_".config::read('adworkmedia','gid')."(); return false;");
        } else { 
            $GeneralButton = ("javascript:initGateway(); return false;"); 
        } 
    }

        $tpl->assign(array(
            'GeneralButton' => $GeneralButton,
            'data' => $data,
            'file_session' => $_SESSION['file_session'][$data['id']]
        ));
        module::$i->on();

    } else page::$i->val('<div id="header"><div id="header-wrapper"><div class="user-error tac">Sorry<br /><strong style="font-size:20px">File not found!!</strong></div></div></div>');

?>
<? ob_flush(); ?>

Plese Help

the problem is because of line 52

header('Content-Disposition: attachment; filename="'.$data['name'].'"');//on commenting this your program will work but not as expected that is downloading the attachment file.Check if somewhere you are using any html content or echo or print statement before this statement.Although adding ob_start() and ob_end_flush() will solve.I have added an example

take a look in

Note:

You can use output buffering to get around this problem, with the overhead of all of your output to the browser being buffered in the server until you send it. You can do this by calling ob_start() and ob_end_flush() in your script, or setting the output_buffering configuration directive on in your php.ini or server configuration files.

which says ob_start() and ob_end_flush()will solve header already send problem
Either use ob_flush() or ob_end_flush() depending on your usage.
ob_flush() - Flush (send) the output buffer
ob_end_flush() - Flush (send) the output buffer and turn off output buffering

More over read this

This function will turn output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer.

The contents of this internal buffer may be copied into a string variable using ob_get_contents(). To output what is stored in the internal buffer, use ob_end_flush(). Alternatively, ob_end_clean() will silently discard the buffer contents.
Output buffers are stackable, that is, you may call ob_start() while another ob_start() is active. Just make sure that you call ob_end_flush() the appropriate number of times. If multiple output callback functions are active, output is being filtered sequentially through each of them in nesting order.

from http://www.php.net/manual/en/function.ob-start.php

Along with example

<?php

function callback($buffer)
{
  // replace all the apples with oranges
  return (str_replace("apples", "oranges", $buffer));
}

ob_start("callback");

?>
<html>
<body>
<p>It's like comparing apples to oranges.</p>
</body>
</html>
<?php

ob_end_flush();

?>

Use headers_sent() function and see where output started. Then mend it!

Also make sure your files don't carry a UTF8 BOM. PHP kind of chokes on it...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.