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

php不接受所有图片扩展名?

发布时间:2020-12-13 16:48:18 所属栏目:PHP教程 来源:网络整理
导读:我正在尝试将我的文件上传到我服务器上的配置文件/目录,我相信一切都可能正常工作……但是在上传时它认为我的jpeg png和gifs不是正确的文件类型.为什么这样做呢.这有什么不对?我如何解决它? function change_profile_image($user_id,$file_temp,$file_extn
我正在尝试将我的文件上传到我服务器上的配置文件/目录,我相信一切都可能正常工作……但是在上传时它认为我的jpeg png和gifs不是正确的文件类型.为什么这样做呢.这有什么不对?我如何解决它?

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` = " . mysql_real_escape_string($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');
       //this is the part i think may be brocken.
       $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="">'; 
}

解决方法

更改爆炸(‘.’,$file_name)爆炸(‘.’,$file_name)

您还需要检查其有效图像,而不仅仅是以图像扩展名结尾.

你的img输出中你也缺少了=你也可以连续3次而不是回声:

echo’< img src =“'.$user_data ['profile'].'”alt =“”>‘;

(编辑:李大同)

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

    推荐文章
      热点阅读