1

I have my Upload File page written in HTML/PHP. The file's content gets stored in a Blob column of an Oracle table. The problem is that it only uploads file that is less than 2 KB and not the greator ones. The code below.

Problem:

Code only works for FileSize < 2 KB.

All these parameters are greator than 2KB.

  • PHP: upload_max_filesize 2M
  • PHP: post_max_size 8M
  • PHP: max_input_time 60

HTML:

Please specify your file: 

<form  method="post" id = "myForm" name = "myForm" enctype="multipart/form-data"  target="upload_target" onsubmit="startUpload();">
<p style = "text-align:center"><img  align = 'middle' src = "logo.jpg" width="50%" height="100"></img></p>

<h3 align = 'center'><font color = 'orange'><u>Text File Upload</u></font></h3>
<div class = "center">
<select id = "selectPol" name = "selectPol"required >
<option value="">Please select file type</option>
<option value="choiceone">Choice One</option>
<option value="choicetwo">Choice Two</option>
</select>
</div>


<div class="center" id = "formDiv">

<br></br><input type="file" name="datafile" id = "datafile" />

<p>
<input type="submit" id = "save" name = "save" value="Upload"/>
<input type="reset" value="Reset" />
</p>

<p style = "text-align:center" id="result"></p>
</div>
<div id = "f1_upload_process" name = "f1_upload_process" style = "text-align:center; display: none;">
<span style = "text-align:center"><font color = "orange"><b>Uploading. Please wait...</b></font></span><br>
<img  align = 'middle' src = "progress_bar.gif"></img>
</div>
</form>
<iframe id="upload_target" name="upload_target" src="#" style="width:0;height:0;border:0px solid #fff;"></iframe>                 
</body>
</html>

PHP:

if(isset($_POST['save']) && $_FILES['datafile']['size'] > 0)
{
$fileName = $_FILES['datafile']['name'];
$fileSize = $_FILES['datafile']['size'];
$tmpName  = $_FILES['datafile']['tmp_name'];
$fileType = $_FILES['datafile']['type'];
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp); 
$conn = OCILOGON("myDB","myDB","MYSERVER");
$qry = "INSERT INTO FilesTable (date_input,file_name,File_CONTENT) VALUES (SYSDATE,'$fileName',utl_raw.cast_to_raw('$content'))";


$stmt = OCIparse($conn,$qry);
ociexecute($stmt);

$result = oci_num_rows($stmt);
Ingila Ejaz
  • 233
  • 3
  • 6
  • 18

1 Answers1

0

The problem was not with PHP file size, the problem was with utl_raw.cast_to_raw('$content') in the query. It has a limitation when inserting more than 2KB in a Blob column.

Replaced my SQL code with:

$qry = "INSERT INTO FilesTable (date_input,file_name,file_content) VALUES (SYSDATE,'$fileName',empty_blob()) RETURNING file_content INTO :file_content";
$stmt = OCIparse($conn,$qry);
$blob = ocinewdescriptor($conn, OCI_D_LOB);
ocibindbyname($stmt, ":file_content", $blob, -1, OCI_B_BLOB);
ociexecute($stmt);
ocicommit($conn);
ocifreestatement($stmt);

And it works :)

Ingila Ejaz
  • 233
  • 3
  • 6
  • 18