PHP上传模块限制文件大小> 2 KB

时间:2015-11-05 11:14:55

标签: php html oracle file blob

我的上传文件页面是用HTML / PHP编写的。文件的内容存储在Oracle表的Blob列中。问题是它只上传小于2 KB的文件而不是大文件。下面的代码。

问题:

代码仅适用于FileSize< 2 KB。

所有这些参数都超过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);

1 个答案:

答案 0 :(得分:0)

问题不在于PHP文件大小,问题在于查询中的utl_raw.cast_to_raw('$content')。在Blob列中插入超过2KB时,它有一个限制。

用以下代码替换我的SQL代码:

$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);

它有效:)