I have a simple input form which contains an input type=”file” with name=”pdf_statement”.
I want to be able to upload the content and insert into the database on the fly. As this is only a test file I am not worried about security (i will add once the functionality is in place).
I have read http://php.net/manual/en/function.stream-get-contents.php but cannot get this to work. I get errors fopen() expects parameter 1 to be string, array given and *stream_get_contents() expects parameter 1 to be resource, boolean given*.
I’m sorry if this is blindingly obvious but for someone who is learning I cannot figure out what I am doing wrong.
<?php
include('session.php');
$provider =$_POST['provider_id'];
$trd_period =$_POST['trading_period_month'];
$pdf_statement =stream_get_contents(fopen($_FILES['pdf_statement'], 'r'));
$sql_qry="update rd_provider_statement
set (pdf_statment='".$pdf_statement."', creation_user_id='SCO')
where provider='".$provider."' and trading_period_month='".$trd_period."'";
$sql_err_no=sql_select($sql_qry,$sql_res,$sql_row_count,$sql_err,$sql_uerr);
?>
You need to open the file in binary mode:
or you can just use
file_get_contents()instead.You also need to sanitize your input. Use
mysql_real_escape_string()