嘿,伙计们,我想我需要对此有新的看法。我有一个插入脚本,可以将数据连同上传到名为 uploads 的文件夹的图像的 URL 一起插入数据库。问题是,虽然所有信息都进入数据库,但图像永远不会上传到文件夹。有谁知道为什么?
<?php
$date=$_POST['date'];
$title=$_POST['title'];
$body=$_POST['body'];
$month=$_POST['month'];
$file = $_FILES['file'];
$name = $file['name'];
$path = "uploads/" . basename($name);
$sql="INSERT INTO content (date, title, body, month, pic_id) VALUES ('$date','$title', '$body', '$month', '" . mysql_real_escape_string($path) . "')";
$result=mysql_query($sql);
if($result && move_uploaded_file($file['tmp_name'], $path) ){
echo 'Query has been inputted into the database';
}
else{
echo 'An error occured';
}
?>
我的 html 看起来像这样:
<h1>Post A Blog </h1></br>
<form name="personal_information" method="post" enctype="multipart/form-data" action="insert.php">
<label>
<span>Date:<br></span><input id="date" type="date" name="date" />
</label><br><br>
<label>
<span>Title:<br></span><input id="title" type="text" name="title" />
</label><br><br>
<label>
<span>Body:<br></span><textarea id="body" type="text" name="body"/></textarea>
</label><br><br>
<label>
<span>Month:<br></span><input id="month" type="text" name="month" />
</label><br><br>
<br>
Upload file:</br>
<input type="file" name="file" id="fileupload"></br></br>
<input type="submit" name="submit" value="Submit" id="submit"/>