I was looking earlier for a way to load a page after a submit and I found that: jquery submit form and then show results in an existing div
The solution is what I expect
$('#create').submit(function() { // catch the form's submit event
$.ajax({ // create an AJAX call...
data: $(this).serialize(), // get the form data
type: $(this).attr('method'), // GET or POST
url: $(this).attr('action'), // the file to call
success: function(response) { // on success..
$('#created').html(response); // update the DIV
}
});
return false; // cancel original event to prevent form submitting
});
But now, I can't upload anything. This is my upload page:
<form method="post" enctype="multipart/form-data" action="../scripts/Test_masse/choix.php" id='create'>
<input type="file" name="fichier"><br/>
<input type="checkbox" name="norme" value="boolean" checked>Conforme aux normes<br/>
<input type="checkbox" name="header" value="boolean" checked>Comporte une en-tête<br/>
<input type="submit" name="upload" value="Uploader"></br>
</form>
And in my choix.php I have
if(isset($_POST['upload'])){
$content_dir = 'upload/';
$tmp_file = $_FILES['fichier']['tmp_name'];
if(!is_uploaded_file($tmp_file)){
exit("Le fichier est introuvable"); //file not found
}
$type_file = $_FILES['fichier']['type'];
if(strstr($type_file, 'application/vnd.ms-excel')==FALSE AND strstr($type_file, 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')==FALSE){
exit("Le fichier n'est pas sous format xls ou xlsx"); //not a xls or xlsx file
}
$name_file = $_FILES['fichier']['name'];
if(!move_uploaded_file($tmp_file, $content_dir . $name_file)){
exit("Impossible de copier le fichier dans $content_dir"); //can't move to upload
}
echo "Le fichier a bien été chargé"; //file successfully uploaded
}
and other lines. So the problem is when I add this script in my upload page, I don't have those output telling me that the file is uploaded or not and my 'upload' folder is empty.
Thanks