duanshanduo3363 2015-03-06 15:15
浏览 27
已采纳

保存在mysql表中时,文件名中不包含文件格式

For some reason when I upload a document and store the file name in mysql table the file name extension isn't included in the name. For example, I upload the pdf file "car.pdf" and the way it is stored in mysql table is "car."(see period right after the word, The file extension is not included). I have checked this website, I have googled it too, but can't find a clear answer.

    $doc_name = mysqli_real_escape_string($dbc, trim($_FILES['doc']['name']));
    $doc_type = $_FILES['doc']['type'];
    $doc_size = $_FILES['doc']['size'];
            if(!empty($title)){
            if(!empty($doc_name)){
                if (($doc_type == 'application/pdf') || ($doc_type == 'application/msword') || ($doc_type == 'application/vnd.openxmlformats-officedocument.wordprocessingml.document')){
                    if(($doc_size > 0) && ($doc_size <= FILE_MAXFILESIZE)){
                        if ($_FILES['doc']['error'] == 0) {
                        $final_name = time() . $doc_name;
                        $target = $uploadpath . $final_name;
                            if(move_uploaded_file($_FILES['doc']['tmp_name'], $target)) {
                                $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die ('There was a problem with your query. Please, contact administrator'); 

                                if(!empty($description)){
                                $query = "INSERT INTO uploaded_files (file, title, description, date_time, user_id, dep_id) VALUES ('$final_name', '$title', '$description', now(), '" . $_SESSION['user_id'] . "', '$dep_id')";
                                }.... rest of the code goes here
  • 写回答

1条回答 默认 最新

  • duankeng9477 2015-03-06 15:43
    关注

    MySQL could truncate the string you're inserting, if the length of the string exceeds what you have in the column definition. In this case, check that the file path name does not have a string name longer than 32.

    Ordinarily, one would expect this INSERT query to fail, but it may not do so if the configuration settings permit.

    If the mysql configuration is under your control (and you desire to avoid this kind of silent truncation of inserted string), start by adding strict_trans_tables to the sql_mode settings in your my.ini (OR my.conf) file.

    Best of luck.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码