我用iframe做了无刷新上传。但是文件过大的时候就取不到文件的大小了。贴上代码,
html页面:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>{title}</title>
<script type="text/javascript">
window.onload = function init()
{
var links = document.getElementById("upa");
links.onclick = uploadFile;
}function uploadFile()
{
var uploadForm = document.getElementById("uploadform");
if (uploadForm)
{
uploadForm.target="fileframe";
uploadForm.action="ajax.php";
}
uploadForm.submit();
}
</script>
</head>
<body>
<form method="post" enctype="multipart/form-data" id="uploadform">
<input type="file" name="thefile" size="30" class="fileinput"/>
<a id="upa" class="uploadfile">Upload File</a>
</form>
<iframe id="fileframe" name="fileframe"></iframe>
</body>
</html>
php:
<?php
print_r($_FILES['thefile']);
$theFile = $_FILES['thefile'];
$tmp_name = $theFile['tmp_name'];
$oldname = strtolower($theFile['name']);
$name = strtolower($theFile['name']);
echo ("<br>File Name:$name<br>");
$ext = substr(strrchr($name, "."), 1);
echo ("<br>File Extention:$ext<br>"); $error = move_uploaded_file($tmp_name, "hamburger/$name");
echo "Column:".$iColumn;
echo "Your file" . $oldname . " was uploaded to ". $actualfilelocation;?>
我想在php中判断上传文件的大小,但是文件一但过大,print_r($_FILES['thefile']);的值就变为null了。请高人帮忙解决下。
html页面:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>{title}</title>
<script type="text/javascript">
window.onload = function init()
{
var links = document.getElementById("upa");
links.onclick = uploadFile;
}function uploadFile()
{
var uploadForm = document.getElementById("uploadform");
if (uploadForm)
{
uploadForm.target="fileframe";
uploadForm.action="ajax.php";
}
uploadForm.submit();
}
</script>
</head>
<body>
<form method="post" enctype="multipart/form-data" id="uploadform">
<input type="file" name="thefile" size="30" class="fileinput"/>
<a id="upa" class="uploadfile">Upload File</a>
</form>
<iframe id="fileframe" name="fileframe"></iframe>
</body>
</html>
php:
<?php
print_r($_FILES['thefile']);
$theFile = $_FILES['thefile'];
$tmp_name = $theFile['tmp_name'];
$oldname = strtolower($theFile['name']);
$name = strtolower($theFile['name']);
echo ("<br>File Name:$name<br>");
$ext = substr(strrchr($name, "."), 1);
echo ("<br>File Extention:$ext<br>"); $error = move_uploaded_file($tmp_name, "hamburger/$name");
echo "Column:".$iColumn;
echo "Your file" . $oldname . " was uploaded to ". $actualfilelocation;?>
我想在php中判断上传文件的大小,但是文件一但过大,print_r($_FILES['thefile']);的值就变为null了。请高人帮忙解决下。
文件过大时的输出结果:
NULL
File Name:File Extention:
Column:Your file was uploaded to文件正常输出结果:Array ( [name] => Microsoft Interview Training.doc [type] => application/msword [tmp_name] => C:\WINDOWS\Temp\phpEC.tmp [error] => 0 [size] => 48128 ) array(5) { ["name"]=> string(32) "Microsoft Interview Training.doc" ["type"]=> string(18) "application/msword" ["tmp_name"]=> string(25) "C:\WINDOWS\Temp\phpEC.tmp" ["error"]=> int(0) ["size"]=> int(48128) }
File Name:microsoft interview training.docFile Extention:doc
Column:Your filemicrosoft interview training.doc was uploaded to
upload_max_filesize = 50M
; Maximum number of files that can be uploaded via a single request
max_file_uploads = 50M