如何在php中获取上传文件的内容?

时间:2021-10-15 21:15:30

I can upload a file by using html file type and then I store that file information to mysql db. Here's my code=>

我可以使用html文件类型上传文件,然后将该文件信息存储到mysql db。这是我的代码=>

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

我的问题是,我无法读取文件内容以将其存储到db。 (我会搜索文件内容,所以我必须阅读文件的内容。)简单地说,如何从URL中读取pdf,doc等文件的内容,例如http://..... /上传/ exampleFile.docx?

1 个解决方案

#1


32  

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

请参阅手册:$ _FILES以获取概述和本教程:Tizag PHP - 文件上载以进行演练。

This PHP Manual section is a must-read as well: Handling File Uploads - moved from hakre's comment.

此PHP手册部分也是必读的:处理文件上传 - 从hakre的评论中移除。

#1


32  

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

请参阅手册:$ _FILES以获取概述和本教程:Tizag PHP - 文件上载以进行演练。

This PHP Manual section is a must-read as well: Handling File Uploads - moved from hakre's comment.

此PHP手册部分也是必读的:处理文件上传 - 从hakre的评论中移除。