20

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?

Olie
  • 24,597
  • 18
  • 99
  • 131
eagle
  • 301
  • 1
  • 2
  • 5

1 Answers1

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

Michael Robinson
  • 29,278
  • 12
  • 104
  • 130
  • This PHP Manual section is a must-read as well: [Handling File UPloads](http://www.php.net/manual/en/features.file-upload.php) – hakre May 05 '12 at 07:42
  • 1
    Thanks michael, i used this code but this output is not understandable for human side.. This code produces output like binary code.For example=>($4��V"e�ˤ9�B��A���)j���T(�y�>vw�餶ث�v�(�SL���qW�U�DX��˿Q�w��4S�^� ��0�F�"м�\�gsld�Y�dL�uH�����݂��c9>)=>output get like this. I can't get output like human understandable – eagle May 05 '12 at 07:47
  • Without extra work you're not going to be able to read doc or pdf files. Refer to http://davidwalsh.name/read-pdf-doc-file-php for a way to do this. – Michael Robinson May 05 '12 at 07:50