Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 22

Thread: upload progress

  1. #11
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    djr33, I am pretty sure you can just use $_FILES['file']['tmp_name']; or somthing like that, pass it trhough a get statement or set a session variable and its done. As for the flash, im not sure the OP is up to it but...
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  2. #12
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I don't believe that's possible: the page is still loading so you can't use PHP yet. The problem here is that you are uploading blind and don't know where the file is going until it's done uploading.

    If you can find a way around this, let me know.

    I may look into this myself... it would be nice.



    Flash is certainly complex/hard, but it's the right way to go to have full control, I think.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #13
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    I dont think you understand the whole idea, or maybe I just wasnt clear.... The submit/uplouad form would appear on page upload.php with an action of upload_submit.php. On that page the php will actually upload the file. It will also set $_FILES['file']['tmp_name'] to say $_SESSION['tmp_name']. In an iframe on that page is upload_progress.php with a query string set by php like
    Code:
     <iframe ... src="upload_progress.php?file=<?php echo $_SESSION['tmp_name']; ?>">
    and then on upload_progress.php, it will recive the filename and then just filesize(); that name, then do all the computations on my previous post....
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  4. #14
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I understand, but the timing still seems uncertain:
    upload_submit.php would not load until the browser has finished sending the upload.

    I wasn't aware you could specify the temporary file's name like that. It could get you around the naming issue, though, perhaps.

    But even if this all works, how do you know the file's size? You could show a display of the progress counting up, but you wouldn't know the percent without knowing the file's whole size.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #15
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I set up a test page and used the minimal form for an upload.

    On the receiving page I had at the top just print_r($_FILES); die();

    The result was this:
    Array ( [userfile] => Array ( [name] => test.mp3 [type] => audio/mpeg [tmp_name] => /tmp/phpqEJth3 [error] => 0 [size] => 301369 ) )

    And it only worked AFTER the upload was completed by the browser.


    I'm almost positive that the browser's request is only sent after the upload is completed, or rather that it's probably part of the request so the PHP script doesn't do anything at all until the data is uploaded.

    I can't find specific info on php.net for this though.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #16
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    This is getting more complex then I thought. If the action of the upload form is GET, (idk if you can with file uploads) there could be a page inbetween that iframes the processing page that through javascript would change another iframe the main window to a query of the tmp_name and ughhhhh this is getting too complecated. maybe you can just find a script online that does this. Or go with flash
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  7. #17
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    PHP only supports POST.

    Your logic isn't wrong-- we just don't have access to those crucial bits of information.


    One other thing to theoretically look into is that PHP also supports the "PUT" method of file uploads. I have no idea what that means (it looks like a command line thing), but php.net has documentation if that helps...

    I'm not sure it's any more useful, but it could be...
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #18
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    After some googling: http://progphp.com/progress.php and the php source:
    PHP Code:
    <?php
    if($_SERVER['REQUEST_METHOD']=='POST') {
      
    $status apc_fetch('upload_'.$_POST['APC_UPLOAD_PROGRESS']);
      
    $status['done']=1;
      echo 
    json_encode($status);
      exit;
    } else if(isset(
    $_GET['progress_key'])) {
      
    $status apc_fetch('upload_'.$_GET['progress_key']);
      echo 
    json_encode($status);
      exit;
    }
    ?>
    <html>
    <head>
    <script type="text/javascript" src="/yui/yahoo.js"></script>
    <script type="text/javascript" src="/yui/event.js"></script>
    <script type="text/javascript" src="/yui/dom.js"></script>
    <script type="text/javascript" src="/yui/animation.js"></script>
    <script type="text/javascript" src="/yui/dragdrop.js"></script>
    <script type="text/javascript" src="/yui/connection.js"></script>
    <script type="text/javascript" src="/yui/container.js"></script>
    <link rel="stylesheet" type="text/css" href="/yui/build/container/assets/container.css" />
    <script type="text/javascript">
    var fN = function callBack(o) {
      var resp = eval('(' + o.responseText + ')');
      var rate = parseInt(resp['rate']/1024);
      if(resp['cancel_upload']) {
        txt="Cancelled after "+resp['current']+" bytes!"; 
      } else {
        txt=resp['total']+" bytes uploaded!";
      }
      txt += "<br>Upload rate was "+rate+" kbps.";
      document.getElementById('pbar').style.width = '100%';
      document.getElementById('ppct').innerHTML = "100%";
      document.getElementById('ptxt').innerHTML = txt;
      setTimeout("progress_win.hide(); window.location.reload(true);",2000);
    }
    var callback = { upload:fN }

    var fP = function callBack(o) {
      var resp = eval('(' + o.responseText + ')');
      if(!resp['done']) { 
        if(resp['total']) {
          var pct = parseInt(100*(resp['current']/resp['total']));
          document.getElementById('pbar').style.width = ''+pct+'%';
          document.getElementById('ppct').innerHTML = " "+pct+"%";
          document.getElementById('ptxt').innerHTML = resp['current']+" of "+resp['total']+" bytes";
        }
        setTimeout("update_progress()",500);
      } else if(resp['cancel_upload']) {
        txt="Cancelled after "+resp['current']+" bytes!"; 
        document.getElementById('ptxt').innerHTML = txt;
        setTimeout("progress_win.hide(); window.location.reload(true);",2000);
      }
    }
    var progress_callback = { success:fP }

    function update_progress() {
      progress_key = document.getElementById('progress_key').value;
      YAHOO.util.Connect.asyncRequest('GET','progress.php?progress_key='+progress_key, progress_callback);
    }

    var progress_win;

    function postForm(target,formName) {
      YAHOO.util.Connect.setForm(formName,true);
      YAHOO.util.Connect.asyncRequest('POST',target,callback);
    /* Is there some event that triggers on an aborted file upload? */
    /*   YAHOO.util.Event.addListener(window, "abort", function () { alert('abort') } ); */
      progress_win = new YAHOO.widget.Panel("progress_win", { width:"420px", fixedcenter:false, underlay:"shadow", close:false, draggable:true, modal:true, effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration:0.3} } );
      progress_win.setHeader("Uploading "+document.getElementById('test_file').value+" ...");
      progress_win.setBody('<div style="height: 1em; width: 400px; border:1px solid #000;"> <div id="pbar" style="background: #99e; height: 98%; width:0%; float:left;">&nbsp;</div> <div id="ppct" style="height: 90%; position: absolute; margin: 1 0 0 185;">0%</div></div><div id="ptxt" style="margin: 3 0 0 5">0 of 0 bytes</div>');
      progress_win.render(document.body);
      update_progress();
    }
    </script>
    </head>
    <body>
     <form enctype="multipart/form-data" id="upload_form" action="" onsubmit="postForm('progress.php','upload_form'); return false;" method="POST">
      <input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="<?php echo uniqid()?>"/>
      <input type="file" id="test_file" name="test_file"/><br/>
      <input type="submit" value="Upload!"/>
     </form>
     <div id="progress_win"> 
        <div class="hd" style="color: #222; background: #bbb"></div> 
        <div class="bd"></div> 
        <div class="ft"></div> 
     </div> 
    </body>
    </html>
    It looks like it uses somthing called APC: http://us.php.net/apc
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  9. The Following 2 Users Say Thank You to fileserverdirect For This Useful Post:

    djr33 (05-16-2010),james438 (05-17-2010)

  10. #19
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    APC is one of those extensions for PHP, which on my shared account is not available. Another extension for PHP is called uploadprogress http://pecl.php.net/package/uploadprogress, but I do not have access to that one either. Perhaps if I upgrade to a premium account I could install PHP extensions on my site.

    Either way it looks like if I want to pursue this I will need to upgrade my GoDaddy account.
    To choose the lesser of two evils is still to choose evil. My personal site

  11. #20
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    This might be another option: http://devpro.it/upload_progress/
    (There's a zip demo to download, with instruction file - dont forget to set the tmp folder value in "whileuploading.php" )

    Here's an online demo of it: http://jemthingsandstuff.co.uk/testi...ress/index.php
    (8MB max file size)

Bookmarks

Posting Permissions

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