更新图像到数据库php


Updating image to database php

所以我的图像没有更新到数据库,我得到这个错误:

Warning: mkdir() [function.mkdir]: No error in C:'xampp'htdocs'phpfinal'pic_upload.php on line 36 error

我谷歌了一下,什么也没找到。请帮助我已经注释掉了第37行

    <?php
    session_start();
    $username = $_SESSION['sUserName']; 
    $conn = mysqli_connect("localhost", "writes", "digger")or die("cannot connect"); 
    mysqli_select_db($conn,phpfinal)or die("cannot select DB");
    ?>
    </head>
    <body>
    <span style="color:#FF0000"><?php echo $msg; ?></span><br />
    <h2>Select File to upload</h2>
    <form enctype="multipart/form-data" action="" method="post">
    <input name="userfile" type="file" />
    <input type="submit" value="Upload"  name="Submit"/>
    </form>
    <?php
    if ((($_FILES["file"]["type"]=='image/gif') || ($_FILES["file"]["type"]=='image/jpeg'))
&& ($_FILES["file"]["size"]<10000000))
    {
    if($_FILES["file"]["error"]>0)
    {
    } else {
    $structure = 'uploaded_files/' .$username ."/";
    }
    }
    if (file_exists ($structure))
    { 
    move_uploaded_file ($_FILES["file"]["tmp_name"], $structure .$_FILES["file"]["name"]);
    $img = $structure .$_FILES["file"]["name"];
} else {
    mkdir($structure);
//line 37
    move_uploaded_file ($_FILES["file"]["tmp_name"], $structure .$_FILES["file"]["name"]);
    $img = $structure .$_FILES["file"]["name"];
}
$sql = "UPDATE users SET structure='image' WHERE username = '$username'";
//I'm not sure if the above line is right or wrong 
$result = mysqli_query( $conn, $sql) or die(error);
print_r($result);
if($result){
echo "Update successful";
}
?>

这是因为你向mkdir发送了一个空字符串(我猜是世界上最糟糕的错误消息;)

检查代码:

if($_FILES["file"]["error"]>0)
{
} else {
  $structure = 'uploaded_files/' .$username ."/";
}

如果你的上传有错误,$structure没有设置。我建议您使用error_reporting(E_ALL)来避免被这类错误所困扰。