douchongzhang9267 2018-06-03 07:15
浏览 29
已采纳

MySQL BLOB只接受图像吗?

Does MySQL BLOB only accept images?

I have been looking online trying to be able to upload larger file sizes of different formats, but I only come across image tutorials.

I have the code below, which fails on the if statement and returns the echo when I upload different file types larger than 10 megs. (the column is LONGBLOB).

<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 'On');  //On or Off

 session_start();
 require_once('connect.php');

    if(isset($_POST['submit'])){
         $file = rand(1000,100000)."-".$_FILES['file']['name'];
         $notes = mysqli_real_escape_string($connection,$_POST['notes']);
         $file_loc = $_FILES['file']['tmp_name'];
         $file_size = $_FILES['file']['size'];
         $file_type = $_FILES['file']['type'];

         $email = mysqli_real_escape_string($connection, $_SESSION['email']);
         $folder="uploads/";

          move_uploaded_file($file_loc,$folder.$file);

            $sql = "INSERT INTO `supportcontent` (`scontentdata`, `scontentnotes`, `suseremail`, `stype`,`ssize`)
            VALUES( '$file','$notes','$email','$file_type ','$file_size')";

            $current_id = mysqli_query($connection, $sql) 
            or die("<b>Error:</b> Problem on Image Insert<br/>" . mysqli_error($connection));
            if (isset($current_id)) {
                header("Location: landingpage.php?upload=success");
            }
        }
        else{       
            echo 'file is 0';
        }   
?>
  • 写回答

2条回答 默认 最新

  • duanchen1937 2018-06-03 07:39
    关注

    Does MySQL BLOB only accept images?

    No, you can store anything you want in it. What's failing when you try to upload a file over 10MB is not the SQL, but the PHP code. Either:

    1. the files size limit. Check the value of the upload_max_filesize and post_max_size settings in the php.ini file.

    2. or the operation timing out. This is more likely to be the culprit especially if you've never changed the default values in your php.ini file. The default timeout in PHP is 30 seconds, so your file must be uploaded in less than 30 seconds. You can change it in the php.ini file using the max_execution_time setting, or it is better to change it in you code using the set_time_limit() function.

    Example, to set the timeout to 2 minutes:

    set_time_limit(120);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵