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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10459864/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 22:13:42  来源:igfitidea点击:

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

php

提问by eagle

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。(我将对文件内容进行搜索,所以我必须阅读文件的内容。)简单地说,我如何从http://...../等网址读取 pdf、doc 等文件的内容上传/exampleFile.docx

回答by Michael Robinson

$fileContent = file_get_contents($_FILES['upload_file']['tmp_name']);

Refer to the manual: $_FILESfor an overview and this tutorial: Tizag PHP - File Uploadfor 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 的评论中移出。