我按照this教程制作了一个图像上传器。它工作得很好,除非我试图上传更大的文件大小:它只是将文件大小“更改”为64 of,并且只显示较大图像的一小部分。因此,我搜索并发现'blob‘的最大文件大小为64 4GB,因此我将其更改为longblob,它的最大文件大小为4GB。
但是现在,试图上传大图片(1MB及更大),我得到的SQL错误'MySQL服务器已经消失‘。当图像小于1MB时,上传工作。文件大小为915 of的1400x900图像上传,而文件大小为1.6mb的1400x900图像无法上传,文件大小为1mb的gif为250x179。看起来,如果文件大小大于1MB,PHP中的SQL insert函数就不再连接了:这怎么可能?
我的php.ini的最大文件大小为32 My,所以这不是问题。我用的是奶爸。
HTML:
<form action="tutorial.php" method="POST" enctype="multipart/form-data">
File:
<input type="file" name="image" > <input type="submit" value="Upload">
</form>PHP:
// connect to database
include 'include/config.php';
// file properties
$file = $_FILES['image']['tmp_name'];
if (!isset($file)){
echo "Please select an image.";
} else {
$image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
$image_name = addslashes($_FILES['image']['name']);
$image_size = getimagesize($_FILES['image']['tmp_name']);
if ($image_size==FALSE){
echo "This is not an image";
}else{
if(!$insert = mysql_query("INSERT INTO gallery VALUES ('', '$image_name', '$image')")){
die(mysql_error());
echo "Problem uploading the image.";
}else{
$lastid = mysql_insert_id();
echo "Image uploaded.<p />Your image:<p /><image src=include/get.php?id=$lastid>";
}
}
}PHP配置:
//database credentials
$username = "root";
$password = "root";
$hostname = "localhost";
//connection to the database
mysql_connect($hostname, $username, $password) or die(mysql_error());
mysql_select_db('imandra') or die(mysql_error());
//echo "Connected to MySQL";PHP get:
include 'config.php';
$id= addslashes($_REQUEST['id']);
$image = mysql_query("SELECT * FROM gallery WHERE id='$id'");
$image = mysql_fetch_assoc($image);
$image = $image['image'];
header("Content-type: image/jpeg");
echo $image;发布于 2014-07-22 11:44:30
您可能需要查看文件(my.cnf)中的设置。
增加max_allowed_packet设置的大小。
max_allowed_packet=50Mhttps://stackoverflow.com/questions/24845443
复制相似问题