如何在数据库中保存大于1MB的图片

时间:2016-09-05 19:22:48

标签: php mysql

嗨,我将照片保存如下:

$cn = mysqli_connect('localhost', 'Admin', 'xkmpfg3t', 'test');

foreach (glob('*.jpg') as $img) {
    $picName = mysqli_real_escape_string($cn, "$img");
    $picData = file_get_contents($img);
    mysqli_query($cn, "INSERT INTO `pictures` (`user_id`,`picture_id`,`picture_name`,`picture`) VALUES ('1','','$picName','$picData')");

   $stmt = mysqli_prepare($cn, "INSERT INTO `pictures` (`user_id`,`picture_id`,`picture_name`,`picture`) VALUES ('1','NULL',?,?)")or die(mysqli_errno($cn));


    mysqli_stmt_bind_param($stmt, "sb",$picName,$picData);


    mysqli_stmt_execute($stmt);

    mysqli_stmt_close($stmt);

}

当图片低于1mb时,每个工作都很好,但是当图片超过1mb时,我只能看到图片的名称。我在我的数据库user_id(int),picture_id(int)PK,picture_name(varchar),picture(mediumblob)中有以下colomns。 my.ini文件的设置为:

[mysqld]
port= 3306
socket = "C:/xampp/mysql/mysql.sock"
basedir = "C:/xampp/mysql" 
tmpdir = "C:/xampp/tmp" 
datadir = "C:/xampp/mysql/data"
pid_file = "mysql.pid"
# enable-named-pipe
key_buffer = 16M
max_allowed_packet = 16M
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 50M
log_error = "mysql_error.log"

post_max_file和upload_max_filesize是256M。我没有收到任何错误或警告一切正常我不知道该怎么办请帮助。

0 个答案:

没有答案