加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 22:46:11 所属栏目:PHP教程 来源:网络整理
导读:我成功地加扰并将图像上传到我的数据库,但是文件路径没有保存到我的sql数据库中的“profile”选项卡.这有什么不对?我如何解决它. ???? include 'core/init.php';function change_profile_image($user_id,$file_temp,$file_extn) {$file_path = 'profile/' .
我成功地加扰并将图像上传到我的数据库,但是文件路径没有保存到我的sql数据库中的“profile”选项卡.这有什么不对?我如何解决它.
????

include 'core/init.php';

function change_profile_image($user_id,$file_temp,$file_extn) {
$file_path = 'profile/' . substr (md5(time()),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_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="">'; 
}


?>

解决方法

你的代码行:

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

看着

`profile` = " . $file_path . "'

你在$file_path的开头忘记了’;)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读