Hello Everyone I want to upload svg it works fine but at a time i convert this svg to png using canvas and then i want to upload both file svg and png. i try a lot but not get any idea.
my code to convert svg to png
var oFReader = new FileReader();
if(file.type.match(/image\/*/)){
oFReader.onloadend = function() {
console.log(oFReader)
var blob = new Blob([this.result], {type: file.type});
var url = URL.createObjectURL(blob);
var image = new Image;
image.src = url;
image.onload = function() {
var canvas = document.querySelector("canvas");
canvas.width = image.width;
canvas.height = image.height;
var context = canvas.getContext("2d");
context.drawImage(image, 0, 0);
var a = document.createElement("a");
a.download = "image.png";
a.href = canvas.toDataURL("image/png");
and code for upload using jquery Ajax
$.ajax({
type: 'POST',
url: 'http://localhost/uploadTest/uploa.php',
data: { svg : $("#myfile").val() , png : pngfile_path},
cache: false,
crossDomain : true,
contentType: false,
processData: false,
success: function(){
console.log("done")
}
}).done(function(dat) {
console.log(dat);
})
and php file
//upload.php
header('Access-Control-Allow-Origin: *');
$output_dir = 'upload/';
echo $_POST["svg"] . "svg---";
echo $_POST["png"] . "png-**";
if ( !file_exists($output_dir) ) {
mkdir ($output_dir, 0777);
}
if(isset($_POST["svg"]))
{
//Filter the file types , if you want.
if ($_POST["svg"]["error"] > 0)
{
echo "Error: " . $_POST["svg"]["error"] . "<br>";
}
else
{
//move the uploaded file to uploads folder;
move_uploaded_file($_POST["svg"]["tmp_name"],$output_dir. $_POST["svg"]["name"]);
echo $_POST["svg"]["name"];
exit;
}
}
?>
i want to upload both file svg and php.. thanks in andvence