I tried to combine the browse button and submit button together .When the button is clicked , Iam able to select the file.
But the file doesn't get uploaded
This is the form
HTML:
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"])?>" method="post" id="myform" enctype="multipart/form-data">
<input type="file" name="upload" id="upload" style="display:none">
<button id="browse">Upload</button>
</form>
JQuery
$(document).ready(function(){
$("#upload").change(function(){
$("#myform").submit();
});
$("#browse").click(function(){
$("#upload").click();
});
});
Then I submitted the data
PHP :
if($_SERVER["REQUEST_METHOD"]=="POST")
{
$file=$_FILES["upload"]["name"];
$folder='uploads/';
$err=$_FILES["upload"]["error"];
$target=$folder.$file;
$temp=$_FILES["upload"]["tmp_name"];
echo $err;
move_uploaded_file($temp, $target);
}
I got the output as 4 . This means that no file was uploaded .How can i resolve this issue?