Upload Progress Bar in PHP

前端 未结 10 1468
栀梦
栀梦 2020-11-22 17:33

Does anyone know how to get a progress bar for an upload in php? I am trying writing code for a photo album uploader. I would like a progress bar to display while the photos

10条回答
  •  一整个雨季
    2020-11-22 17:38

    One PHP-ish (5.2+) & no-Flash way that worked nicely for me:

    First, see this post explaining how to get "uploadprogress" extension up and running.

    Then, in the page containing the form that you are uploading file(s) from, create the following iframe:

    
    

    Next, add this code to your "Submit" button:

    onclick="function set() { f=document.getElementById('progress_iframe'); f.style.display='block'; f.src='uploadprogress.php?id=';} setTimeout(set);"
    

    Now you have a hidden iframe in your form that will come visible and show contents of uploadprogress.php when you click "Submit" to start uploading files. $upload_id must be the same that you are using as the value of hidden field "UPLOAD_IDENTIFIER" in your form.

    The uploadprogress.php itself looks about like this (fix and adjust to your needs):

    
    
    '>
    
    
    Upload progress:

    Note that is self-refreshes every second. You can surely add some nice visual progress bar here (like 2 nested

    s with different colors) if you like. The iframe with upload progress naturally only works while the upload is in progress, and ends its visible life once the form is submitted and browser reloads to the next page.

提交回复
热议问题