Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 778
eagle Avatar asked May 05 '12 07:05

eagle


People also ask

How can I access my uploaded files in PHP?

1 Answer. Show activity on this post. $fileContent = file_get_contents($_FILES['upload_file']['tmp_name']);

How do you get the uploaded file information in the receiving script?

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.

How can I view uploaded image in PHP?

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('.


1 Answers

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

like image 139
Michael Robinson Avatar answered Oct 17 '22 09:10

Michael Robinson