Javascript function does not summarize $ _POST of PHP

0

I'm implementing a progress bar in a simple file upload script. I have the three files that are giving me a headache, Upload.php where the upload script is located, script.js where the script that updates the progress bar is located, and finally index.php where the upload form is.

The upload panel is a form that sends with the $_POST the trigger to the PHP file, and it always worked fine, after I implemented this script ( script.php ) began to give problem, the progress bar works, but the upload script in PHP is triggered.

index.php

<form action="" method="post" enctype="multipart/form-data">
     <input type="file" name="pic" />
     <!-- ........ -->
<button type="submit" name="btn-upload">Upload file</button> <!-- botão de upload -->

<div class="progress">
    <div class="bar"></div >
    <div class="percent">0%</div >
</div>

<!--scripts include-->

<!-- jQuery Library-->
<script type="text/javascript" src="js/jquery.min.js"></script>

<!-- jQuery Form Plug in -->
<script type="text/javascript" src="js/jquery.form.min.js"></script>

<!-- our main javascript file -->
<script type="text/javascript" src="js/script.js"></script>

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

script.js

$(document).ready(function() {
    /* variables */
    var percent = $('.percent');
    var bar = $('.bar');

    /* submit form with ajax request */
    $('form').ajaxForm({

        /* set data type json */
        dataType:  'json',

        /* reset before submitting */
        beforeSend: function() {
            bar.width('0%');
            percent.html('0%');
        },

        /* progress bar call back*/
        uploadProgress: function(event, position, total, percentComplete) {
            var pVel = percentComplete + '%';
            bar.width(pVel);
            percent.html(pVel);
        },

    });
});

upload.php

(View complete file)

// muitas funções que uso na função abaixo
//
if(isset($_POST['btn-upload']))
{
    $original = $_FILES['pic']['name'];
    $array = explode('.', $original);

So, by summary, the problem is caused when I click the upload button, the progress bar walks, but the file is not sent, because the PHP upload function is not called.

  

I've tried to put a echo 'debug'; in the file upload.php to see if the function was called at least, but nothing appeared on the page.

    
asked by anonymous 02.02.2017 / 23:10

1 answer

0

I could not find in your jquery code the string with the URL that points to the uploads.php file. this is required if not by default it sends to the same form page.

Make this change to see the result.

    
03.02.2017 / 07:18