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 is situated the script that updates the Progress bar and finally the index.php
where is the upload form.
The upload panel is a form
that sends with the $_POST
Trigger for the PHP file, and it always worked right after I implemented this script (script.php
) began to give trouble, the progress bar works, but the PHP upload script 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
// muitas funções que uso na função abaixo
//
if(isset($_POST['btn-upload']))
{
$original = $_FILES['pic']['name'];
$array = explode('.', $original);
So, in 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 putting a
echo 'debug';
in the archiveupload.php
to see if at least the function was called, but nothing appeared on the page.
You can pass the complete upload.php file?
– Rodrigo Jarouche
Updated question.
– CypherPotato
But the form ta no action, and from what I saw, no AJAX request is made pro upload.php. How will HTML know where to send this form?
– André
the button
btn-upload
in the form will generate an event in thePost
, i am a beginner in PHP/HTML, for all I know, this is what happens in the code, always worked.– CypherPotato
Do the following in the form action puts action="upload file path.php"
– Rodrigo Jarouche
I just did that, it redirects the page and shows only what the file sent but the home page
index.php
some...– CypherPotato