ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Progress bar for your uplaods ! [PHP- APC- APACHE]

September 09, 2010 3:53pm

Subscribe [3]
  • #1 / Sep 09, 2010 3:53pm

    Kronick

    3 posts

    Hi all,
    today, I’ll show you how you can integrate that progress bar :
    http://www.johnboy.com/php-upload-progress-bar/
    to your application.
    First, make sure you installed APC into your server.
    Basically, the flow will be :
    -> an id is created for the apc key by the form
    -> that id is catched by javascript in order to display a frame which contains the progress bar
    -> we use apc_fetch in order to obtain the download’s status
    -> we submit that value to the jquery which will handle the progress bar animation

    I’ve created two controllers : the first one displays the form, the second one the progress bar.
    The progress bar uses the uri routing in order to ask apc the status
    Final uri :
    http://localhost/fr/docs/user/progress/874d7a1baf6cf26ff405d48d6d41b197

    What I changed :
    into the form view :

    $('#upload_frame').attr('src','<?php echo site_url(); ?>/docs/user/progress/<?php echo $up_id; ?>');

    You notice that I display the key into an extra segment
    Progress view :
    if($this->uri->segment(7))
    I check the seventh segment created here :

    $.get("<?php echo site_url(); ?>/docs/user/progress/<?php echo $this->uri->segment(5); ?>/randval/"+ Math.random(), {

    Controller (docs/user/) :

    function Add_document () {
            if($_SESSION['login'] == "") {
                redirect(MYACCOUNT, 'location');
            }
            else {
                $this->load->helper('form');
                $this->load->view('docs/actions/add', $data);
            }
        }
    
        function Progress() {
            $data['PROGRESS_KEY']= $this->input->post('progress_key');
           $this->load->view('docs/progress', $data);
        }


    View (docs/actions/add) :
    <html>
    <head><title>Foo</title>

    <?php $up_id = md5(uniqid(rand())); ?>
    <!--Get jQuery-->
    [removed][removed]
    
    <!--display bar only if file is chosen-->
    [removed]
        $(document).ready(function() {
            //show the progress bar only if a file field was clicked
            var show_bar = 0;
            $('input[type="file"]').click(function(){
                show_bar = 1;
            });
    
            //show iframe on form submit
            $("#form1").submit(function(){
                if (show_bar === 1) {
                    $('#upload_frame').show();
                    function set () {
                        $('#upload_frame').attr('src','<?php echo site_url(); ?>/docs/user/progress/<?php echo $up_id; ?>');
                    }
                    setTimeout(set);
                }
            });
        });
    [removed]
    </head>
    <body>
     <form action="<?php echo site_url(); ?>/docs/actions/upload" method="POST" enctype="multipart/form-data" name="form1" id="form1">
                        <!--APC hidden field-->
                        <input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="<?php echo $up_id; ?>"/>
                        <!---->
        
                                    <input id="file" type="file" name="user_file">
        </form>   
    
    
    <!--Include the iframe-->
                                    <iframe id="upload_frame" name="upload_frame" frameborder="0" border="0" src="" scrolling="no" scrollbar="no" > </iframe>
    
    
          
    </body>
    </html>

    the progress view

    <?php
        $url = basename($_SERVER['SCRIPT_FILENAME']);
        // Get file upload progress information.
        if($this->uri->segment(7)) {
            $status = apc_fetch('upload_'.$this->uri->segment(5));
            echo $status['current']/$status['total']*100;
            die;
        }
        ?>
    [removed][removed]
    <link href="<?php echo $BASE_URL; ?>style_progress.css" rel="stylesheet" type="text/css" />
    
    [removed]
        $(document).ready(function() {
            //
    
            setInterval(function()
            {
                $.get("<?php echo site_url(); ?>/docs/user/progress/<?php echo $this->uri->segment(5); ?>/randval/"+ Math.random(), {
                },
                function(data)    //return information back from jQuery's get request
                {
                    $('#progress_container').fadeIn(100);    //fade in progress bar
                    $('#progress_bar').width(data +"%");    //set width of progress bar based on the $status value (set at the top of this page)
                    $('#progress_completed').html(parseInt(data) +"%");    //display the % completed within the progress bar
                }
            )},500);    //Interval is set at 500 milliseconds (the progress bar will refresh every .5 seconds)
        });
    [removed]
    
    <body id="progress_back">
        <!--Progress bar divs-->
        <div id="progress_container">
            <div id="progress_bar">
                <div id="progress_completed"></div>
    
            </div>
    
        </div>
        <div id="loader"></div>
        <!---->
    </body>


    Final result 😊
    http://img193.imageshack.us/img193/2290/prout20100909at84750pm.jpg

  • #2 / Sep 09, 2010 3:54pm

    Kronick

    3 posts

    The css file :

    /*iframe*/
    #upload_frame {
        border:0px;
        height: 35px;
        width: 330px;
        display:none;
    }
    
    #progress_back {
        margin: 0px;
        background-color: #fafafa;
    }
    #progress_container {
        float: left;
        width: 310px; 
        height: 20px; 
        border: 1px solid #CCCCCC; 
        background-color:#EBEBEB;
        display: block;
    }
    
    #progress_bar { 
        background-repeat: repeat-x; 
        background-image: url(img/mydocs/progress/back.gif); 
        float: left; 
        height: 20px; 
        background-color: #d8e8eb; 
        width: 0%; 
        z-index:10; 
    }
    
    #progress_completed {
        text-shadow: 1px 1px #585858;
        margin-top: 0px;
        font-family: Helvetica, Verdana, Arial, sans-serif;
        font-size: 15px; 
        z-index:40; 
        line-height: 20px; 
        padding-left:4px; 
        color: #e1e1e1;
    }
    
    #loader {
        float: left;
        background-position: 2px 4px;
        height: 20px;
        width: 18px;
        background-image: url(img/mydocs/progress/loader.gif);
        background-repeat: no-repeat;
    }
  • #3 / Sep 09, 2010 4:19pm

    echoDreamz's avatar

    echoDreamz

    77 posts

    APC is not a viable caching solution for Windows (atleast with IIS). Wincache is the only solution for Windows and IIS.

    Thanks for this though, I will see if this can be updated to support Wincache.

  • #4 / Sep 09, 2010 4:33pm

    Kronick

    3 posts

    Hi echoDreamz, I read a lot of threads dealing with APC under windows, what do you mean by “not viable” ?
    thanks 😊

  • #5 / Sep 09, 2010 5:23pm

    echoDreamz's avatar

    echoDreamz

    77 posts

    APC and IIS do not work well together. The implementation of FastCGI with PHP on IIS and APC still results in an unstable caching solution, however WinCache was developed by Microsoft specifically for IIS and PHP.

  • #6 / Sep 09, 2010 5:39pm

    Kronick

    3 posts

    Alrighty, thanks for the info, i’ll edit my post so people understand my tuto fits more Apache’s environments.

  • #7 / Feb 22, 2011 5:20am

    indian

    1 posts

    Hi gr8 script

    I need your help for user this at zend framework

    while set this script in mvc structure its not working

    My controller name is catlog and action is upload


    public function uploadAction()
      {


    $objRequest = $this->getRequest();
    if ($objRequest->isPost()) {
    //get unique id
    $up_id = uniqid();
    //print $up_id;exit;
    $this->view->up_id=$up_id;
    //process the forms and upload the files
    if ($_POST) {

    //specify folder for file upload
    $url = getcwd ();
    $folder =$url."/images/catlog_image/";

    //specify redirect URL
    //$redirect = "upload.php?success";
    $uccess="success";
    $redirect = "/coffee_table/public/admin/catlog/upload/success/".$uccess;

    //upload the file
    move_uploaded_file($_FILES["file"]["tmp_name"], "$folder" . $_FILES["file"]["name"]);

    //do whatever else needs to be done (insert information into database, etc…)

    //redirect user
    header('Location: '.$redirect); die;
    }
          }
         
      }
    and progress action

    public function uploadprogressAction()
      {
    $layout = Zend_Layout::getMvcInstance();
    $layout->setLayout('popup');

    $progress_key = $this->_getParam('progress_key');
    //print $progress_key;exit;
    $this->view->progress_key=$progress_key;

    }

    and
    at upload view
    $(’#upload_frame’).attr(‘src’,’<?php echo SERVER_PATH ?>;/admin/catlog/uploadprogress/progress_key/<?php echo $up_id; ?>;’);


    and progress view

    $.get(”<?php echo site_url(); ?>;/admin/catlog/uploadprogress/progress_key/<?php echo $this->progress_key; ?>;/randval/”+ Math.random()

    $url = basename($_SERVER[‘SCRIPT_FILENAME’]);
      // Get file upload progress information.
      if($this->progress_key) {
    $status = apc_fetch('upload_'.$this->progress_key);
    echo $status['current']/$status['total']*100;
    die;

     


    with this i am not able to get progress bar…. its give me some id 1.124578 ander browse

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases