gpt4 book ai didi

php - 从 HTML 表单上传图像以及其他表格条目,同时使用图像信息更新表格

转载 作者:行者123 更新时间:2023-11-30 00:28:28 24 4
gpt4 key购买 nike

我有一个 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.";
}
}
?>

关于php - 从 HTML 表单上传图像以及其他表格条目,同时使用图像信息更新表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22691873/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com