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

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php不接受所有图片扩展名?脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试将我的文件上传到我服务器上的配置文件/目录,我相信一切都可能正常工作……但是在上传时它认为我的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 =“”>‘;

脚本宝典总结

以上是脚本宝典为你收集整理的php不接受所有图片扩展名?全部内容,希望文章能够帮你解决php不接受所有图片扩展名?所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。