In upload.php i have the following form
<form action="upload.php" method="POST" id="upload" enctype="multipart/form-data">
<input type="file" name="file" id="file"/>
<input type="button" value="Insert" onclick='$.post("file.php", { command: "upload", file:$("input[type=file]#file").val()}, function(data){ $("#message").html(data); });'/>
</form>
<span id="message"></span>
In file.php the upload syntax in as following:
if($_POST['command'] == 'upload'){
$dir = "/public_html/";
if (!is_dir($dir)) mkdir($dir, 0777);
$file = $_FILES['file']['name'];
$path = $dir . '/'. $file;
if (move_uploaded_file ($_FILES['file']['tmp_name'], $path)) {
echo $file. 'was successfully uploaded';
}else{
echo $file. 'was not uploaded';
}
}
I'm unable to get the name and data of file through onclick event. Any comment shall be well appreciated. This is a quite simple and very basic upload syntax but I want to know if the file name along with file data can be parsed this way from html form for processing in application server.