我的PHP代码只会上传小文件,例如20mb,所以当我尝试上传超过该文件的文件时,它会说什么都不返回,但无论如何它都会插入到数据库中。我尝试过上传大小,但它没有做任何事情。脚本应该在将信息插入要使用的数据库时上载swf文件和图像。为什么上传的内容不能超过20mb。
<?php
$link = $_POST['link'];
if(isset($_POST['upload'])) {
$allowed_filetypes = array('.swf');
$max_filesize = 999999999999999999999999999999999999999999999;
$upload_path = 'swf/';
$game = $_POST['game'];
$category = $_POST['category'];
$swf = $_POST['swf'];
$height = $_POST['height'];
$width = $_POST['width'];
$radio=".swf";
$characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
$done = '';
for ($i = 0; $i < 25; $i++)
$done .= $characters[mt_rand(0, 61)];
$filename = $done . '' . $radio;
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
if(!in_array($ext,$allowed_filetypes))
die('The file you attempted to upload is not allowed');
if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
die("The file you attempted to upload is too large");
if(!is_writable($upload_path))
die('You cannot upload to the specified directory, please CHMOD it to 777. ');
if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename)) {
$query = "INSERT INTO image (title, description) VALUES ($filename, $description)";
mysql_query($query);
echo 'Game Added Successfully';
$doney = $website . '' . $filename;
echo "<br/>";
echo $doney;
$result = $upload_path . '' . $filename;
} else {
echo 'There was an error during the file upload. Please try again Later.';
}
}
?>
<br/>
<?php
if(isset($_POST['upload'])) {
$allowed_filetypes = array('.jpg');
$max_filesize = 999999999999999999999999999999999999999999999999999999;
$upload_path = 'gameimg/';
$game = $_POST['game'];
$category = $_POST['category'];
$swf = $_POST['swf'];
$height = $_POST['height'];
$width = $_POST['width'];
$radio=".jpg";
$characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
$done = '';
for ($i = 0; $i < 25; $i++)
$done .= $characters[mt_rand(0, 61)];
$filename = $done . '' . $radio;
$link="/game?id=".$done;
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
if(!in_array($ext,$allowed_filetypes))
die('The file you attempted to upload is not allowed');
if(filesize($_FILES['filez']['tmp_name']) > $max_filesize)
die("The file you attempted to upload is too large");
if(!is_writable($upload_path))
die('You cannot upload to the specified directory, please CHMOD it to 777.');
if(move_uploaded_file($_FILES['filez']['tmp_name'],$upload_path . $filename)) {
$query = "INSERT INTO image (title, description) VALUES ($filename, $description)";
mysql_query($query);
echo 'Game Added Successfully';
$doney = $website . '' . $filename;
echo "<br/>";
echo $doney;
$resulty = $upload_path . $filename;
} else {
echo 'There was an error during the file upload. Please try again Later.';
}
}
?>
答案 0 :(得分:2)
显然,您的服务器不支持大文件。使用phpinfo();
查看php.ini文件的内容。检查phpinfo()中的upload_max_filesize
。它位于php信息的Core
部分下。
编辑:同时检查post_max_size
,它也位于phpinfo核心部分下面(@TheSexiestManinJamaica评论中指出)。并按照@ceejayoz
post_max_size