I have a huge application in Javascript and other libraries, but now I want to add another feature, adding images via an upload. I´ve found multiple, working examples, but when i try to integrate that in my application nothing happens. Things just don´t work. I´m quite stuck now.
Firstly this is the image upload I found:
http://phppot.com/php/php-ajax-image-upload/
But when I integrate it in my application it just doesnt work.. There aren't any errors in the console.
Maybe a problem is the fact I use multiple POST data to get this right, because I already had a huge POST data for the whole application. I can't get it working with integrating it all in 1 POST but maybe that is a possibility..
I'm so stuck right now. Here are some of the codes:
This is the part of the JS which get called when pressed on the upload button
jQuery("#uploadForm").submit(function(e) {
console.log('upload die handel');
e.preventDefault();
jQuery.ajax({
url: "upload.php",
type: "POST",
data: new FormData(this),
contentType: false,
cache: false,
processData:false,
success: function(data)
{
console.log('upload die handel');
$("#logouploadtekst").html('Great success!');
$("#logouploadtekst").append(data);
},
error: function()
{
$("#logouploadtekst").html('Great failure!');
}
});
});
This is the file which get called...
<?php
if(is_array($_FILES)) {
if(is_uploaded_file($_FILES['userImage']['tmp_name'])) {
$sourcePath = $_FILES['userImage']['tmp_name'];
$targetPath = "images/".$_FILES['userImage']['name'];
if(move_uploaded_file($sourcePath,$targetPath)) {
?>
<img src="<?php echo $targetPath; ?>" />
<?php
}
}
}
?>
I actually want to send an email with the image with, so I don't really know if it's necessary to upload the image, but I think it's better to do (right?)
EDIT: It seems the the upload.php doesn't work. Can it be that I cannot call 2 different PHP Post scripts? Because First I try to call the upload.php to upload the logo, and then I show it on my page, after that the client finishes the app and presses submit again to send the email. So I do get the console.log in the AJAX call, but the data doesn't get through..