Hey. This code works in most browsers, and even partially in IE6. It uploads files less 10Mb (approximately), but not anything larger. The code specifies that those files are permitted.
嘿。此代码适用于大多数浏览器,甚至部分在IE6中。它上传的文件少于10Mb(大约),但不是更大的文件。该代码指定允许这些文件。
Also, note that it seems like the entire file seems to be transferred to the servers before disregarded.
另外,请注意,似乎整个文件似乎在被忽视之前传输到服务器。
The website is at: www.mgxvideo.com/mgxcopy-alpha-3/ and can be reached by adding an item in the cart, and then clicking the upload function. Ideas?
该网站位于:www.mgxvideo.com/mgxcopy-alpha-3/,可以通过在购物车中添加项目,然后单击上传功能来访问。想法?
Here is the form:
这是表格:
<form enctype="multipart/form-data" action="upload_files.php?order_id=<?php echo $_GET['order_id'] ?>" method="POST">
<table style="width:100%">
<tr>
<td valign="top">
<span class="style1">Choose a file to upload: </span>
</td>
<td valign="top">
<input name="uploadedfile" type="file" />
</td>
</tr>
</table>
<input type="submit" value="Upload File" />
<input type="hidden" name="action" value="add"/>
<input type="hidden" name="MAX_FILE_SIZE" value="100000000" />
</form>
Here is a line at the top of upload_files.php:
这是upload_files.php顶部的一行:
$upload_output = upload_file($customer_id, $_REQUEST['action'], $_GET['order_id'], $_FILES);
And here is the upload_file() code:
这是upload_file()代码:
function upload_file($customer_id, $action, $upload_id, $FILES)
{
$target_path = "uploads/";
$target_path = $target_path . $customer_id . '_' . $upload_id . '_' . basename( $FILES['uploadedfile']['name']);
$str_output = '';
if ($action == 'del' and file_exists($_POST['filepath']))
{
delete_file($customer_id, $_POST['filepath']);
$str_output = '<span class="style1">File successfully deleted. If you are done uploading files, ' .
'<a href="#" onclick="self.close();">click here</a> to close this window.</span>';
setcookie("upload_out_txt", $str_output, time() + 300);
setcookie("upload_out_b", "1", time() + 300);
} else if ($action == 'add')
{
if (count_uploads($customer_id, $upload_id) >= 2)
{
$str_output = '<span class="style1">Problem: You have reached the maximum allowed uploads for this particular order. Please delete a file before continuing.</span>';
setcookie("upload_out_txt", $str_output, time() + 300);
setcookie("upload_out_b", "1", time() + 300);
} else if (file_exists($target_path))
{
$str_output = '<span class="style1">Problem: A version of the file you are trying to upload already exists. Please delete the file from out servers before uploading again.</span>';
setcookie("upload_out_txt", $str_output, time() + 300);
setcookie("upload_out_b", "1", time() + 300);
} else if (move_uploaded_file($FILES['uploadedfile']['tmp_name'], $target_path))
{
insert_to_database('uploaded_files', array($customer_id, $upload_id, 'now()', $target_path));
$str_output = '<span class="style1">Success. The file was successfully uploaded. If you are done, <a href="" onclick="window.close();">click here to close the window</a></span>';
setcookie("upload_out_txt", $str_output, time() + 300);
setcookie("upload_out_b", "1", time() + 300);
} else
{
$str_output = '<span class="style1">There was an error uploading the file, please try again!</span>';
setcookie("upload_out_txt", $str_output, time() + 300);
setcookie("upload_out_b", "1", time() + 300);
}
}
return $str_output;
}
Here is my php.ini file, after I tried to implement a fix:
在我尝试实现修复之后,这是我的php.ini文件:
extension_dir="/kunden/homepages/30/d93769495/htdocs/extensions";
extension=uploadprogress.so;
upload_max_filesize=150M;
post_max_size=210M;
max_input_time=1800;
file_uploads=1;
memory_limit=240M;
max_execution_time=1800;
2 个解决方案
#1
Check the following settings in php.ini
:
检查php.ini中的以下设置:
-
upload_max_filesize
needs to be greater than 10 MiB (10M
).upload_max_filesize需要大于10 MiB(10M)。
-
post_max_size
needs to be at least 40% greater thanupload_max_filesize
.post_max_size需要比upload_max_filesize至少大40%。
The reason why this is required is that some old user-agents will upload using base64 encoding, which adds a 37% overhead to the data. Add mime headers, other post parameters, there are plenty of reasons to have it higher than upload_max_filesize
.
需要这样做的原因是一些旧的用户代理将使用base64编码上传,这会增加37%的数据开销。添加mime标头,其他帖子参数,有很多理由让它高于upload_max_filesize。
-
max_input_time
needs to be at least 900 (15 minutes).
max_input_time需要至少900(15分钟)。
You want to give enough time for the user to upload its file.
您希望为用户提供足够的时间来上传其文件。
#2
This may not fix it but on one thread i was reading it said that IE6 needs to process the MAX_FILE_SIZE line before the filename input. So try moving the following line to the top of the form:
这可能无法修复它,但在我读它的一个线程上说IE6需要在文件名输入之前处理MAX_FILE_SIZE行。因此,请尝试将以下行移至表单顶部:
<input type="hidden" name="MAX_FILE_SIZE" value="100000000" />
I have no idea if it works and IE6 requires it to be parsed in that order, but that is what the thread I was reading said the solution was.
我不知道它是否有效,IE6要求按顺序解析它,但这就是我正在阅读的线程所说的解决方案。
Also check your php.ini max file size and timeout.
还要检查你的php.ini最大文件大小和超时。
#1
Check the following settings in php.ini
:
检查php.ini中的以下设置:
-
upload_max_filesize
needs to be greater than 10 MiB (10M
).upload_max_filesize需要大于10 MiB(10M)。
-
post_max_size
needs to be at least 40% greater thanupload_max_filesize
.post_max_size需要比upload_max_filesize至少大40%。
The reason why this is required is that some old user-agents will upload using base64 encoding, which adds a 37% overhead to the data. Add mime headers, other post parameters, there are plenty of reasons to have it higher than upload_max_filesize
.
需要这样做的原因是一些旧的用户代理将使用base64编码上传,这会增加37%的数据开销。添加mime标头,其他帖子参数,有很多理由让它高于upload_max_filesize。
-
max_input_time
needs to be at least 900 (15 minutes).
max_input_time需要至少900(15分钟)。
You want to give enough time for the user to upload its file.
您希望为用户提供足够的时间来上传其文件。
#2
This may not fix it but on one thread i was reading it said that IE6 needs to process the MAX_FILE_SIZE line before the filename input. So try moving the following line to the top of the form:
这可能无法修复它,但在我读它的一个线程上说IE6需要在文件名输入之前处理MAX_FILE_SIZE行。因此,请尝试将以下行移至表单顶部:
<input type="hidden" name="MAX_FILE_SIZE" value="100000000" />
I have no idea if it works and IE6 requires it to be parsed in that order, but that is what the thread I was reading said the solution was.
我不知道它是否有效,IE6要求按顺序解析它,但这就是我正在阅读的线程所说的解决方案。
Also check your php.ini max file size and timeout.
还要检查你的php.ini最大文件大小和超时。