我有一个HTML表单,这是两个条目和一个图像。我试图将图像上传到"目标"文件夹,然后将超链接到我的SQL数据库中的图像,以便将来检索,同时还添加了我的其他2个条目形式。我已经遵循了一些教程,我仍然不能得到这个工作。目前mySQL正在为日期和条目工作。没有任何图片被输入到表中,也没有图片被上传到目标。
HTML代码
<table border="0" cellpadding="3" cellspacing="1">
<form enctype="multipart/form-data" action="mob_create.php" method="post">
<tr>
<td width="150">Date:</td></tr><tr>
<td><input type="date" name="inputDate" value="" /> </td>
</tr>
<tr>
<td>Entry:</td></tr><tr>
<td width="300"><input size="34" type="text" name="inputEntry" value="" /></td>
</tr>
<tr>
<td width="150">Add an image (Optional):</td></tr><tr>
<td><input type="file" name="inputPic" accept="image/*" /></td></tr>
<tr>
<td><input type="submit" name="submit" /></td>
</tr>
</form>
</table>
PHP代码
session_start();
include 'includes/Connect.php';
$target = "http://www.aam.prettypottery.ie/upload/";
$target = $target . basename( $_FILES['inputPic']['name']);
$date = $_POST['inputDate'];
$entry = $_POST['inputEntry'];
$picture = ($_FILES['inputPic']['name']);
$username=$_SESSION['myusername'];
if(!$_POST['submit']) {
echo "Please complete all entries of the form";
} else {
mysql_query("INSERT INTO `$username` (`Date`,`Entry`,`Picture`) VALUES('$date','$entry','$picture')") or die(mysql_error());
if(move_uploaded_file($_FILES['inputPic']['tmp_name'], $target)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
}
?>
目标的路径需要是本地的
还要确保目标文件夹是可写的。
session_start();
include 'includes/Connect.php';
$target = "upload/";
$target = $target . basename( $_FILES['inputPic']['name']);
$date = $_POST['inputDate'];
$entry = $_POST['inputEntry'];
$picture = ($_FILES['inputPic']['name']);
$username=$_SESSION['myusername'];
if(!$_POST['submit']) {
echo "Please complete all entries of the form";
} else {
mysql_query("INSERT INTO `$username` (`Date`,`Entry`,`Picture`) VALUES('$date','$entry','$picture')") or die(mysql_error());
if(move_uploaded_file($_FILES['inputPic']['tmp_name'], $target)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
}
?>