php – 在遗留MySQL驱动程序中插入BLOB会导致“消失”错误

前端之家收集整理的这篇文章主要介绍了php – 在遗留MySQL驱动程序中插入BLOB会导致“消失”错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我按照this教程制作了一个图像上传器.它工作正常,除非我尝试上传更大的文件大小:它只是将文件大小“更改”为64KB并且只显示较大图像的一小部分.所以,我用Google搜索并发现’blob’的最大文件大小为64kb,因此我将其更改为longblob,其最大文件大小为4GB.

但现在,尝试上传大图像(1MB或更大),我得到sql错误MysqL服务器已经消失’.对于小于1MB的图像,上传工作.上传文件大小为915kb的1400×900图像,但文件大小为1.6mb的1400×900图像不上传.上传了一个250×179的gif,文件大小为1mb.看起来如果文件大小大于1MB,PHP中的sql插入函数就不再连接了:这怎么可能?

我的PHP.ini的最大文件大小为32MB,所以这不是问题.我正在使用MAMP.

HTML:

  1. PHP" method="POST" enctype="multipart/form-data">
  2. File:

PHP

  1. // connect to database
  2. include 'include/config.PHP';
  3. // file properties
  4. $file = $_FILES['image']['tmp_name'];
  5. if (!isset($file)){
  6. echo "Please select an image.";
  7. } else {
  8. $image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
  9. $image_name = addslashes($_FILES['image']['name']);
  10. $image_size = getimagesize($_FILES['image']['tmp_name']);
  11. if ($image_size==FALSE){
  12. echo "This is not an image";
  13. }else{
  14. if(!$insert = MysqL_query("INSERT INTO gallery VALUES ('','$image_name','$image')")){
  15. die(MysqL_error());
  16. echo "Problem uploading the image.";
  17. }else{
  18. $lastid = MysqL_insert_id();
  19. echo "Image uploaded.

    PHP?id=$lastid>";

  20. }

  21. }

  22. }

PHP配置:

  1. //database credentials
  2. $username = "root";
  3. $password = "root";
  4. $hostname = "localhost";
  5. //connection to the database
  6. MysqL_connect($hostname,$username,$password) or die(MysqL_error());
  7. MysqL_select_db('imandra') or die(MysqL_error());
  8. //echo "Connected to MysqL";

PHP得到:

  1. include 'config.PHP';
  2. $id= addslashes($_REQUEST['id']);
  3. $image = MysqL_query("SELECT * FROM gallery WHERE id='$id'");
  4. $image = MysqL_fetch_assoc($image);
  5. $image = $image['image'];
  6. header("Content-type: image/jpeg");
  7. echo $image;
最佳答案
您可能需要查看MysqL配置文件(my.cnf)中的设置.

增加max_allowed_pa​​cket设置的大小,例如

  1. max_allowed_packet=50M

猜你在找的HTML相关文章