<input type="file" id="file" name="file[]" multiple/>
html
var uploadfile = $('#file').val();
$.ajax({
type: 'POST',
url: '../include/addimage.php',
dataType: "text",
data: {
file: uploadfile
},
success: function(data) {
alert(data);
}error: function(data) {
alert(data);
}
Ajax Request JS
If(0 < ($_FILES["file"]['size']){
echo "file is set"
}else{
echo "No file"
}
Php code
The code above is my code to test if a file is ready to be uploaded in database. I always get No file
even if i put a file in input text
UPDATE
Based on the sample from here
$fileName = $_FILES['file']['name'];
$fileType = $_FILES['file']['type'];
$fileSize = $_FILES['file']['size'];
$fileError = $_FILES['file']['error'];
$fileContent = file_get_contents($_FILES['file']['tmp_name']);
$fp = fopen($fileName, 'rb'); // read binary
i get the file using the code above and i turn the file into blob. But i get fopen(whomovedmycheese - Copy.pdf): failed to open stream: No such file or directory in
in line $fp = fopen($fileName, 'rb'); // read binary
. What seems to be the problem here?
Update
i used $_FILES['file']['tmp_name']
and it is ok now