php文件路径/文件扩展名未保存到sql中的数据库

php文件路径/文件扩展名未保存到sql中的数据库,php,sql,image,filepath,Php,Sql,Image,Filepath,我正在成功地对图像进行置乱并将其上载到数据库,但是文件路径没有保存到sql数据库中的“配置文件”选项卡。这里怎么了?我该怎么修呢。 include 'core/init.php'; function change_profile_image($user_id, $file_temp, $file_extn) { $file_path = 'profile/' . substr (md5(time()), 0, 10) . '.' . $file_extn; move_uploaded_file

我正在成功地对图像进行置乱并将其上载到数据库,但是文件路径没有保存到sql数据库中的“配置文件”选项卡。这里怎么了?我该怎么修呢。
include 'core/init.php';

function change_profile_image($user_id, $file_temp, $file_extn) {
$file_path = 'profile/' . substr (md5(time()), 0, 10) . '.' . $file_extn;
move_uploaded_file($file_temp, $file_path);
mysql_query("UPDATE `users` SET `profile` = " . $file_path . "' WHERE `user_id` = " . (int)$user_id);

}

 if (isset($_FILES['profile']) === true) {
    if (empty($_FILES['profile']['name']) === true) {
       echo 'y u no choose file!';
  } else {
       $allowed = array ('jpg', 'jpeg', 'gif', 'png');

       $file_name = $_FILES['profile']['name'];
       $file_extn = strtolower(end(explode ('.', $file_name)));
       $file_temp = $_FILES['profile']['tmp_name'];

       if (in_array($file_extn, $allowed) === true) {
        change_profile_image($session_user_id, $file_temp, $file_extn);

        header('Location: dontdelete.php');
        exit();

       }else {
        echo 'y u no jpg or png or gif';       

       }
  }
 }

if (empty($user_data['profile']) === false) {
    echo '<img src"', $user_data['profile'], '" alt="">'; 
}


?>
包括“core/init.php”;
函数更改\u配置文件\u图像($user\u id、$file\u temp、$file\u extn){
$file_path='profile/'.substr(md5(time()),0,10)。'.$file_extn;
移动上传的文件($file\u temp,$file\u path);
mysql\u查询(“更新`users`SET`profile`=”$file\u path。“”其中`user\u id`=”(int)$user\u id);
}
如果(isset($_FILES['profile'])==true){
if(空($_文件['profile']['name'])==true){
回显“您没有选择文件!”;
}否则{
$allowed=数组('jpg','jpeg','gif','png');
$file\u name=$\u FILES['profile']['name'];
$file_extn=strtolower(end(explode('.',$file_name));
$file\u temp=$\u FILES['profile']['tmp\u name'];
if(在数组中($file\u extn,$allowed)==true){
更改配置文件映像($session\u user\u id、$file\u temp、$file\u extn);
标题('Location:dontdelete.php');
退出();
}否则{
回音“YU无jpg或png或gif”;
}
}
}
if(空($user_data['profile'])==false){
回声';
}
?>
您的代码行:

mysql_query("UPDATE `users` SET `profile` = " . $file_path . "' WHERE `user_id` = " . (int)$user_id);

`profile` = " . $file_path . "'

您在
$file_path
;的开头忘记了一个“)

上帝保佑你。我希望这能解决问题。我现在就给它打个漩涡!嗯,这似乎不是问题。我把“$file_path.”改为“'.$file_path.”@kiahm这很奇怪,你能把
var_转储(mysql_error())放进去吗之后?我得到的布尔(真)警告:无法修改标题信息-标题已由我发送修复了标题问题。。。仍然无法修复文件路径为什么只选择md5哈希的前10个字符(40位数据而不是128位)?为什么要使用md5呢?如果两次上传在同一秒发生了什么?我不确定我只是觉得10个字符看起来更漂亮。是的,但是没有人会看文件名,这增加了名称冲突的可能性。我将只使用用户id作为文件名。