• Register now to get access to thousands of Tutorials, Leaked content, Hot NSFW and much more. Join us as we build and grow the community.

Advertise Here

Advertise Here

Advertise Here

File Upload With Progress Bar Using PHP

stiflas

Network Sniffer Expert
S Rep
0
0
0
Rep
0
S Vouches
0
0
0
Vouches
0
Posts
73
Likes
37
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 2 1000 XP
Good Day!!!

In this tutorial, we are going to make File Upload With Progress Bar Using PHP. In the example below, we have file input field and progress bar. During the uploading file, we are going to show the progress bar if it is done already.

And, also, we have to use the jQuery and AJAX function to do this functionally.

HTML File Form

We have a source code for our progress bar and file input field.

  1. <center

    >
  2. <form

    id

    =

    "upload_container"

    action

    =

    "upload.php"

    method

    =

    "post"

    >
  3. <div

    >
  4. <label

    >

    Upload Image File:</

    label

    >
  5. <input

    name

    =

    "userImage"

    id

    =

    "userImage"

    type

    =

    "file"

    class

    =

    "demoInputBox"

    /

    >
  6. </

    div

    >
  7. <br

    /

    >
  8. <div

    ><input

    type

    =

    "submit"

    id

    =

    "btnSubmit"

    value

    =

    "Submit"

    class

    =

    "btnSubmit"

    /

    ></

    div

    >
  9. <div

    id

    =

    "progress-div"

    ><div

    id

    =

    "progress-bar"

    ></

    div

    ></

    div

    >
  10. <div

    id

    =

    "targetLayer"

    ></

    div

    >
  11. </

    form

    >
  12. <div

    id

    =

    "loader-icon"

    style

    =

    "display:none;"

    ><img

    src

    =

    "loading.gif"

    /

    ></

    div

    >
  13. </

    center

    >

jQuery Script

This is the script for a progress bar, and it will be increased if the progress completed.

  1. <script src="js/code_js.js" type="text/javascript"></script>

  2. <script src="js/code_js1.js" type="text/javascript"></script>

  3. <

    script type=

    "text/javascript"

    >
  4. $(

    document)

    .ready

    (

    function

    (

    )

    {
  5. $(

    '#upload_container'

    )

    .submit

    (

    function

    (

    e)

    {
  6. if

    (

    $(

    '#userImage'

    )

    .val

    (

    )

    )

    {
  7. e.preventDefault

    (

    )

    ;
  8. $(

    '#loader-icon'

    )

    .show

    (

    )

    ;
  9. $(

    this

    )

    .ajaxSubmit

    (

    {
  10. target:

    '#targetLayer'

    ,
  11. beforeSubmit:

    function

    (

    )

    {
  12. $(

    "#progress-bar"

    )

    .width

    (

    '0%'

    )

    ;
  13. }

    ,
  14. uploadProgress:

    function

    (

    event,

    position,

    total,

    percentComplete)

    {
  15. $(

    "#progress-bar"

    )

    .width

    (

    percentComplete +

    '%'

    )

    ;
  16. $(

    "#progress-bar"

    )

    .html

    (

    '<div id="progress-status">'

    +

    percentComplete +

    ' %</div>'

    )
  17. }

    ,
  18. success:

    function

    (

    )

    {
  19. $(

    '#loader-icon'

    )

    .hide

    (

    )

    ;
  20. }

    ,
  21. resetForm:

    true
  22. }

    )

    ;
  23. return

    false

    ;
  24. }
  25. }

    )

    ;
  26. }

    )

    ;
  27. </

    script>

And, this is the output.

1_27.png


For my next tutorial, we are going to create a multiple image upload.

Share us your thoughts and comments below. Thank you so much for dropping by and reading this tutorial post. For more updates, don’t hesitate and feel free to visit this website more often and please share this with your friends or email me at [email protected]. Practice Coding. Thank you very much.


Download
You must upgrade your account or reply in the thread to view the hidden content.
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

452,499

349,821

349,831

Top