Php 注意:未定义的索引:"$file=$\u POST[';file';]&引用;

Php 注意:未定义的索引:"$file=$\u POST[';file';]&引用;,php,Php,使用$\u FILES['file']而不是$\u POST。无法使用$\u POST访问文件。 而且 文件名未更新的原因,请使用变量$File\u Name而不是$File <?php $file = $_POST['file']; $conn = mysql_connect("localhost","root","") or die(mysql_error); $db = mysql_select_db("no_tiny");

使用
$\u FILES['file']
而不是
$\u POST
。无法使用$\u POST访问文件。 而且

文件名未更新的原因,请使用变量
$File\u Name
而不是
$File

<?php

$file = $_POST['file'];

            $conn = mysql_connect("localhost","root","") or die(mysql_error);
                $db = mysql_select_db("no_tiny");


?>

<?php





if (isset($_FILES['file']['name'])) {
    $File_Name = $_FILES['file']['name'];

    $File_Extension = strtolower(substr($File_Name,strpos ($File_Name,'.')+1));

    $File_Type = $_FILES['file']['type'];

    $File_Size = $_FILES['file']['size'];

    $max_Size = 200000;


    $tmp_name = $_FILES ['file']['tmp_name'];


    if (!empty($File_Name)){

        if(($File_Extension == 'jpeg' || $File_Extension == 'jpg') && $File_Type == 'image/jpeg'  || $File_Type == 'image/jpg' && $File_Size <= $max_Size ){    

            $File_Location = 'Upload/';
            if(move_uploaded_file($tmp_name, $File_Location.$File_Name)){

                echo 'File has been Successfully Uploaded';
                $sql = "INSERT into yes (Image) values ('$file')";
                $q = mysql_query($sql); 


            }else{
                echo 'An Error was Encounter while Uploading. ';
            }
        }else{
            echo 'File must be jpeg/jpg and 2.5mb less';
        }
    }else {
        echo 'Noob';
    }


}

?>


<form action = "upload.php" method = "POST" enctype = "multipart/form-data">
<input type = "file" name =  "file"><br /> <br />
<input type =  "submit" value = "Upload">

</form>
$\u文件
-HTTP文件上载变量

print_r($_FILES['file'])

样本输出:

  $sql = "INSERT into yes (Image) values ('$File_Name')";
  $q = mysql_query($sql); 

Ref:

因为fie是一个文件,它不是通过post访问的,所以你应该试试$\u FILES['file']

这个问题似乎离题了,因为它是。
[file] => Array
    (
        [name] => filename (comes from the browser, so treat as tainted)
        [type] => file type  (not sure where it gets this from - assume the browser, so treat as tainted)
        [tmp_name] => /tmp/php/php1h4j1o (could be anywhere on your system, depending on your config settings, but the user has no control, so this isn't tainted)
        [error] => UPLOAD_ERR_OK  (= 0)
        [size] => 123   (the size in bytes)
    )