CSS-Regex Posted February 12, 2021 Share Posted February 12, 2021 I am not able to get this to work at all. <div id="container"> <form id="myform" method="POST" enctype="multipart/form-data"> <div class="textInput"> <input type="file" name="file" id="file"> </div> <button type="submit" id='btn' value="Submit">Add Photo</button> </form> </div> <script> $(document).ready(function(){ $('#btn').click(function (e) { e.preventDefault(); let formData = new FormData(); let file = $('#file')[0].files[0]; formData.append('file', file); $.ajax({ url: 'upload.php', type: 'post', contentType: false, processData:false, success: function(data){ if (data != 0){ alert('success' + data); } else { alert('error'); } }, }); }); }) </script> I have tried other methods, but this is not succeeding the upload.php file is as follows <?php $filename = $_FILES['file']['name']; $location = '/upload/'.$filename; if (move_uploaded_file($_FILES['file']['tmp_name'], $location)){ echo $location; } else { echo 0; } Quote Link to comment Share on other sites More sharing options...
CSS-Regex Posted February 12, 2021 Author Share Posted February 12, 2021 I've solved the problem of what it says in the <b> tag elements, I had to put isset() Around the $_FILES global variables I'm still getting an error though, where it should upload the file Quote Link to comment Share on other sites More sharing options...
Solution CSS-Regex Posted February 13, 2021 Author Solution Share Posted February 13, 2021 I have an issue with the php code Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.