2

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

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";
}
?>
4

1 回答 1

0

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

检查您的代码:

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

如果您的上传有错误,则$structure未设置。我建议您使用 error_reporting(E_ALL) 以避免陷入此类错误。

于 2013-04-30T15:09:50.847 回答