Php 图片上传不工作

标签 php html css

我正在尝试使用 PHP 将图像上传到文件,我是该语言的新手,因此非常感谢您的帮助。要上传的图像来自带有 from 输入的页面,代码似乎没有执行!非常感谢,这是我的代码(第一个 html,第二个 php): 我正在尝试使用 PHP 将图像上传到文件,我是该语言的新手,因此非常感谢您的帮助。要上传的图像来自带有 from 输入的页面,代码似乎没有执行!非常感谢,这是我的代码(第一个 html,第二个 php):

<?php
    include_once 'Includes/dbh.inc.php';
    session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo $_SESSION['user']; ?></title>
<link href="https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300|Tajawal|Quicksand|Raleway:100" rel="stylesheet">
<link rel="stylesheet" tyle="text/css" href="main.css">
</head>
<body>
    
<!-- START Header -->
    
    <section class="headuser">
        <div class="pagetitle">
            C A T C H Y .
        </div>
        
        <div class="username">
            <a href="UserProfile.php"><?php echo $_SESSION['user']; ?></a>  
        </div>
    </section>          
<!-- END Header -->

<!-- START Bio -->
    <section class="Bio">
        <div class="friends">
            <br>freinds<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
        </div>  

        <div class="editbio">
            <?php echo $_SESSION['user']; ?>
            
            <form action="Includes/upload.php" id="bioimage" method="POST" enctype="multipart/form-data">
                <input type="file" name="profileup">
                <button type="submit" id = "submit" name="upload">Use!</button>
            </form>
            <form action="Includes/Post.inc.php" id="bioform" method="POST">
                <textarea name="Text1" id= "content" placeholder="Tell everyone who you are" cols="50" rows="10"></textarea>
                <br>
                <button type="submit" id="submit" name="submit">Post!</button>
            </form>
        </div>
    </section> 
<!-- END Bio -->
</body>
</html>

    if(isset($_POST['submit'])) {
            $file = $_FILES['profileup'];

            $fileName = $_FILES['profileup']['name'];
            $fileTmpName = $_FILES['profileup']['tmp_name'];
            $fileSize = $_FILES['profileup']['size'];
            $fileError = $_FILES['profileup']['error'];
            $fileType = $_FILES['profileup']['type'];

            $fileExt = explode('.', $fileName);
            $fileActualExt = strtolower(end($fileExt));

            $allowed = array('jpg', 'jpeg', 'png');

            if (in_array($fileActualExt, $allowed)){

                if ($fileError === 0){

                    if ($fileSize < 1000000){
                        $filenamenew = uniqid('', true).".".$fileActualExt;
                        $filedest = 'profileimages/'.$filenamenew;
                        move_uploaded_file($fileTmpName, $filedest);
                        header("Location: ../UserProfile.php?suc");
                    }else{
                        echo "your file was to big";
                    }

                }else{
                    echo "There was an error uploading your file";
                }

            }else{
                echo "you cant upload files of this type";
            }
    }else{
        header("Location: ../UserProfile.php?fail");
    }    
?>

最佳答案

我认为您可以使用按钮名称“上传”。

if(isset($_POST['submit']))

当您提交图像时,它必须有效。

if(isset($_POST['upload'])) 

关于Php 图片上传不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49954884/

相关文章:

php - 将此字符串转换为日期格式以保存到 mysql

php - MySQL - 在同一查询中使用多个 LEFT JOIN 语句

php - 使用 Git ‘去同步化’一个 PHP 配置文件

jquery - 使用 jQuery 滚动到灯箱 div 的顶部

css - 如何将 Bootstrap 4 导航栏元素对齐到底部

php - 播放视频 - 服务器配置不正确 - 12939

HTML5 按钮不会与文本区域的最右侧对齐

php - 需要按日期水平显示记录

html - 引导汉堡导航栏不会工作

css - javaFX : styleClass is not working in jar file