-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Michael Trefzer edited this page Jul 4, 2016
·
2 revisions
For this example the following dependencies are used:
- The core phpMussel repository: phpMussel
- This phpMussel-plugin: plugin-resultAsJson
- Used for asynchronos file upload with jquery: bifrost
Setup a php project with these dependencies according to their documentations.
Use this code as
index.html:
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8"/>
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width,initial-scale=1"/>
<title>Testing file uploads with phpMussel</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
<script src="jquery.bifrost.js"></script>
</head>
<body>
<form id="myForm">
<input type="file" name="file" id="file">
<hr>
<button id="send">send</button>
<hr>
<div id="results">results</div>
</form>
<script>
$(document).ready(function () {
$("#send").click(function () {
var options = {
url: 'upload.php',
method: 'POST',
dataType: 'iframe json',
fileInputs: $('#file'),
data: {text: $('#text').val(), hidden: $('#hidden').val()},
success: function (data) {
$("#results").html(JSON.stringify(data));
},
error: function (jqXHR, textStatus, errorThrown) {
$("#results").html('Request failed! ' + textStatus + ' | ' + errorThrown);
}
};
$.ajax(options);
return false;
});
});
</script>
</body>
</html>
This php-script is called to process the uploaded file. Add it to the base folder.
upload.php:
<?php
require_once "phpmussel/phpmussel.php";
/**
* This code is only reached if the scan of phpMussel is passed successfully.
* If you like to save or manipulate the uploaded file you can access it
* via the global $_FILES array.
*/
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
echo json_encode(array("message" => "passed phpMussel"));
This file, last edited: 4th July 2016 (2016.07.04).