I am trying to do a simple pdf/excel file upload by storing the file into an upload folder and saving the name into the database. The problem here is that after i click on the upload button, the database saves my $transaction->test = "something"; but not the file or directory.
<input type="file" id="upload" name="upload" accept="application/pdf,application/vnd.ms-excel" />
<input id="next" class="btn btn-primary" type="button" value="Upload" />
<script>
uploadFile : function (upload) {
$.ajax({
type: 'POST',
url: 'upload.php',
data: {
upload: $('#upload').val(),
},
success: function(data)
{
if(data.result == true){
alert("File has been uploaded successfully");
}
else{
alert("Fail to upload file");
}
},
});
return false;
}
</script>
upload.php
public function uploadFile($params){
extract($params);
$response = $this->response;
$agentId = $this->getCurrentId();
$agent = Investor::fetch($agentId); //fetching user info
if(count($POST)>0){
$d=(object)$POST;
$transaction = new Transaction (); //create new data
$transaction->test = "something"; //this works
$target_dir = "../uploads/";
$target_file = $target_dir . basename($_FILES["upload"]["name"]);
$fileUpload = move_uploaded_file($_FILES['upload']['tmp_name'], $target_file);
if($fileUpload){
$transaction ->description = $fileUpload;
$transaction->save ();
$this->success();
$this->response['result'] = true;
}
else{
$this->response['result'] = false;
}
}
return $this->response;
}