php图片上传无效

时间:2017-01-31 19:51:25

标签: php

在我对代码进行更改之前,我已经问过这个问题,而且我的图片上传完全没有用,我已经检查了用户名密码,而Root这些都是正确的。我的代码不会显示任何错误我不知道该怎么办可以有人请帮帮我吗?我出于安全原因更改了连接

<?php 

$con = mysqli_connect("localhost", "torcdesi_jone45", "password", "torcdesi_amazing");
if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$query_image = 'INSERT INTO shirt_table (images3) 
                values( "' . $_FILES['file3']['name'] . '")';
?>
<?php

include("configur.php");
if($_POST) { 
    // $_FILES["file"]["error"] is HTTP File Upload variables $_FILES["file"] "file" is the name of input field you have in form tag.

     if ($_FILES["file3"]["error"] > 0) {
        // if there is error in file uploading 
        echo "Return Code: " . $_FILES["file3"]["error"] . "<br />";
    } else {
        // check if file already exit in "images" folder.
        if (file_exists("shirtimgs/" . $_FILES["file3"]["name"])) {
        } else { 
            //move_uploaded_file function will upload your image. 
            if(move_uploaded_file($_FILES["file3"]["tmp_name"],"shirtimgs/" . $_FILES["file3"]["name"]))
            {
                // If file has uploaded successfully, store its name in data base
                $query_image = "insert into shirt_table";

                if(mysqli_query($link, $query_image)) {
                    echo "Stored in: " . "shirtimgs/" . $_FILES["file3"]["name"];
                } else {   
                    echo'';
                }
            }
        }
    }
 }
 ?>

1 个答案:

答案 0 :(得分:3)

正如我在评论中所述,您的表单缺少处理文件的正确enctype。

我知道,因为我看到your other question在表单中没有包含它。

<form enctype="multipart/form-data" action="__URL__" method="POST">

根据手册: