所以我的图片没有更新到数据库,我收到了这个错误:
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";
}
?>
答案 0 :(得分:0)
这是因为你向mkdir发送一个空字符串(我猜这个世界上最糟糕的错误信息;)
检查您的代码:
if($_FILES["file"]["error"]>0)
{
} else {
$structure = 'uploaded_files/' .$username ."/";
}
如果上传时出错,则未设置 $ structure 。我建议你使用error_reporting(E_ALL)来避免陷入这样的错误。