【问题标题】:PHP Uploading Module restricts filesize > 2 KBPHP 上传模块限制文件大小 > 2 KB
【发布时间】:2016-02-06 04:55:14
【问题描述】:

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

问题:

代码仅适用于 FileSize

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

【问题讨论】:

  • 我没有使用 oci_* 库的经验,但是看起来你的 $fileName 变量很容易受到 SQL 注入的影响。
  • 您可以将更多的表单放入源代码中吗?例如,它是否在文件输入之前包含一个 MAX_FILE_SIZE 隐藏字段?
  • @GordonM 代码中没有隐藏字段..
  • @GordonM 请查看已编辑的问题.. 你可能有个好主意

标签: php html oracle file blob


【解决方案1】:

问题不在于 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);

它有效:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-26
    • 1970-01-01
    • 2019-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-05
    相关资源
    最近更新 更多