上传文件时文件名正在更改

时间:2017-05-27 10:30:23

标签: php mysqli

我创建了一个可以将文件上传到数据库的页面。但是,只要文件名上有特殊字符,它就会在数据库中更改它的名称。例如,我有一个名为Biñan.pdf的pdf文件,它改为BIÃ'AÃ'.pdf

这是我的上传文件的功能。

<?php

function upload_image()
{
    if ( isset($_FILES["user_image"]) )
    {
        $destination = './upload/' . $_FILES['user_image']['name'];
        move_uploaded_file($_FILES['user_image']['tmp_name'], $destination);
        return $_FILES['user_image']['name'];
    }
}

function get_image_name($user_id)
{
    include('db3.php');
    $statement = $connection->prepare("SELECT image FROM users10 WHERE id = '$user_id'");
    $statement->execute();
    $result = $statement->fetchAll();
    foreach($result as $row)
    {
        return $row["image"];
    }
}

function get_total_all_records()
{
    include('db3.php');
    $statement = $connection->prepare("SELECT * FROM users10");
    $statement->execute();
    $result = $statement->fetchAll();
    return $statement->rowCount();
}

?>

1 个答案:

答案 0 :(得分:0)

保存转储备份并尝试将数据库,表格和字段的字符集更改为 UTF-8

对于数据库

ALTER DATABASE <database_name> CHARACTER SET utf8 COLLATE utf8_unicode_ci;

表格

ALTER TABLE <table_name> CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;

对于列(请注意字段类型关键字)

ALTER TABLE <table_name> MODIFY <column_name> VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci;