如何获取PHP中上传文件的内容? [英] How can i get the content of uploaded file in php?
问题描述
我可以使用html文件类型上传文件,然后将该文件信息存储到mysql db.这是我的代码=>
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.)
我的问题是,我无法读取文件内容以将其存储到db. (我将在文件内容上进行搜索,因此我必须阅读文件的内容.)简而言之,我如何从诸如
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']);
有关概述,请参见手册: $_FILES
本教程: Tizag PHP-文件上传进行演练.
Refer to the manual: $_FILES
for an overview and this tutorial: Tizag PHP - File Upload for a walkthrough.
此PHP手册部分也是必读内容:处理文件上传-从hakre的评论中移出.
This PHP Manual section is a must-read as well: Handling File Uploads - moved from hakre's comment.
这篇关于如何获取PHP中上传文件的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!