简体   繁体   中英

How can i get the content of uploaded file in php?

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 ?

$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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM