I can upload a file by using html file type and then I store that file information to mysql db. Here's my code=>
$upload = wp_upload_bits($_FILES["upload_file"]["name"], null, file_get_contents($_FILES["upload_file"]["tmp_name"]));
$document_name = $_FILES['upload_file']['name'];
$document_link = $upload['url'];
//and DB Operations in here..(I store to db filename,date,filelink etc.)
My problem is, I can't read the file content to store it to db. (I will do search on the file content, so I must read content of file.) Briefly how can i read the content of a file like pdf, doc or etc. from url such as http://...../uploads/exampleFile.docx?
1 Answer. Show activity on this post. $fileContent = file_get_contents($_FILES['upload_file']['tmp_name']);
To get the basic information of the uploaded files, PHP provides a $_FILES predefined array which is explained below in detail. $_FILES Array: The $_FILES is a predefined & two dimensional associative global array that helps to receive a script to get the information about the uploaded file via the HTTP post method.
Show activity on this post. Show activity on this post. //file_upload. php if(isset($_FILES['image'])){$errors= array(); $file_name = $_FILES['image']['name']; $file_size = $_FILES['image']['size']; $file_tmp = $_FILES['image']['tmp_name']; $file_type = $_FILES['image']['type']; $file_ext=strtolower(end(explode('.
$fileContent = file_get_contents($_FILES['upload_file']['tmp_name']);
Refer to the manual: $_FILES
for an overview and this tutorial: Tizag PHP - File Upload for a walkthrough.
This PHP Manual section is a must-read as well: Handling File Uploads - moved from hakre's comment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With