2015-11-05 147 views
1

我有用HTML/PHP編寫的上傳文件頁面。該文件的內容存儲在Oracle表的Blob列中。問題是它只上傳小於2 KB的文件,而不是較大的文件。下面的代碼。PHP上傳模塊限制文件大小> 2 KB

問題:

代碼只對文件大小< 2 KB。

所有這些參數都大於2KB。

  • PHP:upload_max_filesize的2M
  • PHP:8M的post_max_size
  • 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

的可能的複製http://stackoverflow.com/questions/3263480/upload-max-size-in-php – Amarnasan

+1

我沒有用'oci_ *'lib中的經驗但是它肯定看起來你很容易受到SQL注入你的'$ fileName'變量。 –

+0

你可以將更多的表單放入源代碼中嗎?例如它是否包含文件輸入前的MAX_FILE_SIZE隱藏字段? – GordonM

回答

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

而且它的工作原理:)

相關問題