waka waka - 1 month ago 17
PHP Question

move_uploaded_file() only uploads small files

I want to implement a small file upload on a web portal. I found this solution on PHP.net:

<form action='action.php' method='post' enctype="multipart/form-data">
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<!-- Name of input element determines name in $_FILES array -->
Send this file:
<input name="userfile" type="file"/>
<!-- hidden input fields to sent variables to action.ph -->
<innput type="hidden" name='casenumber' id="caseForFileUpload" />
<input type="hidden" name='key' id="keyForFileUpload" />
<input type="submit" value="Send File" name="uploadfiles"/>

and this is the relevant part of

$target_dir = "upload/";
$target_file = $target_dir.basename($_FILES['userfile']['name']);
$fileType = pathinfo($target_file,PATHINFO_EXTENSION);

if($fileType == "pdf"){
if(move_uploaded_file($_FILES['userfile']['tmp_name'], $target_file)){
echo "<br><br>File uploaded";
echo "<br><br>File could not be uploaded";

This works well for small files <150KB, but fails for files larger than that and I don't know why this is happening.

Relevant info from

upload_max_filesize = 20M
post_max_size = 20M
max_execution_time = 30
max_input_time = 60

So it really should work for files that are larger than 150KB. There is no message in the PHP log and no
is used that may override these settings.

Where else can I look to track down this behavior or how else can I implement a file upload to allow file sizes for up to 2MB?

PS: Please also note that the server is still running with PHP 5.2.17 and that it's not in my power to update it to a newer version.

Answer Source

As request by the OP:

name="MAX_FILE_SIZE" value="30000"

That is 30,000 bytes. As per the manual http://php.net/manual/en/features.file-upload.post-method.php

"The MAX_FILE_SIZE hidden field (measured in bytes)".

Either remove that input, or increase it.