0

I have an HTML form that sends over the file to be uploaded in php via a form submission. I would rather not change the page when clicking submit and do a bunch of other functions. What is the simplest way of doing that with AJAX?

<form action="upload.php" method="post" enctype="multipart/form-data">
    <label style="font-size:18px; font-weight:bold; padding-right:10px"> Select MP3 or WAV file to upload:</label>
    <input type="file" name="fileToUpload" id="fileToUpload" style="background-color:lightgrey">
    <input style="float:right;margin-right:10px" type="submit" value="Upload File" name="submit" onsubmit="return validateForm()">
</form>
SamG
  • 303
  • 4
  • 13

1 Answers1

0

you could attach the file to a query param and retrieve it with $_Get or put it inside a session variable and retrieve it that way.

<form action="upload.php?<? echo $_SERVER['QUERY_STRING']; ?>" method="post">
<label style="font-size:18px; font-weight:bold; padding-right:10px"> Select MP3 or WAV file to upload:</label>
<input type="file" name="fileToUpload" id="fileToUpload" style="background-color:lightgrey">
<input style="float:right;margin-right:10px" type="submit" value="Upload File" name="submit" onsubmit="return validateForm()">
</form>

<? #option two
$_SESSION['file'] = $_POST['fileToUpload]; ?>

without seeing more code I can only give a very vague answer.