I am trying to call a Javascript function inside the PHP file upload. PHP method taken from here:
<?php
$post_id = $_GET['post_id'];
$ds = DIRECTORY_SEPARATOR;
$storeFolder = '/images/$post_id';
if (!empty($_FILES)) {
$tempFile = $_FILES['file']['tmp_name'];
$targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds;
$targetFile = $targetPath. $_FILES['file']['name'];
move_uploaded_file($tempFile,$targetFile);
echo "<script type='text/javascript'>showfeaturedimg('$post_id');</script>";
}
?>
The file upload works with no problem.
I have tried multiple ways, which I found on different forums, but none of them work:
echo "<script language='javascript'>showfeaturedimg('$post_id');</script>";
or
echo "<script>showfeaturedimg(\''$post_id'\');</script>";
The showfeaturedimg() function simply makes an AJAX call to retrieve the stored image from a database and display it on the page without reloading the page.
Furthermore have tried to add a javascript function call to the queuecomplete of Dropzone, however does not work either:
<form action="upload-post.php?post_id=<?php echo $post_id;?>" class="dropzone" id="news-dropzone">
<div class="fallback">
<input name="file" type="file" multiple="multiple" />
</div>
</form>
<script>
Dropzone.options.dropzoneJsForm = {
init: function () {
this.on("success", function (file) {
alert("All files have uploaded ");
});
}
};
</script>
What am I doing wrong?
echois infile.xhr.response. Then you can take this response and add it to the page so it gets executed. Can you show your dropzone configuration?