可能是一个小的东西,但我累了,不知道为什么它不工作,我不能问我的老师,因为今天是星期天,我想保留今天的程序。
我有一个cms的表单。在那里你可以更新该页面的文本,但我也希望能够上传图像。然而,当我将我的标签ect
用于图像上传时,我得到了很多错误。
在下面的代码中,我有一个表单,用于在我想要的代码下上传。我把//Here
放在我想要的地方。所以你们知道我想要什么。谢谢你的帮助。
<?php
$sql = "SELECT * FROM home";
$result = mysqli_query($db, $sql);
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
echo "<h3>Gegevens van record " . $row["ID"] . "</h3>";
echo "<form name='update{$row["ID"]}'
<form action='cms_home_update.php' method='POST'>
<input type='hidden' name='id' value='{$row["ID"]}'>
<p>Titel</p>
<input type='text' name='Titel' size='75' value='{$row["Titel"]}'><br><p>Tekst</p>
<textarea name='Tekst' rows='10' cols='100'>";
echo html_entity_decode(stripslashes($row["Tekst"]), ENT_QUOTES);
echo "</textarea><br>
//Here i wanted to have to be able to also upload a image
<input type='submit' name='button' value='Updaten'>
</form>";
echo"<h3>Plaatje van " . $row["ID"] . "</h3>";
?>
//Here i have the upload form how to make it to be able to standing on here i wanted
<form action="cms_home_image.php" method="post"
enctype="multipart/form-data">
<label for="file">Kies je bestand.</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Versturen">
</form>
<?php
}
?>
首先,这有一些建设性的错误:
打开两个<form>
标签:
echo "<form name='update{$row["ID"]}'
<form action='cms_home_update.php' method='POST'>
您还必须转义$row
数组索引周围的引号,因为您也使用双引号"
开始字符串:
"…$row['"ID'"]…"
或者连接您的值:
"…".$row["ID"]."…"
要更新文件,您需要以下input
元素:
<input type="file" name="file" id="file">
然后在你的PHP
脚本上,你可以使用任何这些来处理对象(引用w3c页面:PHP文件上传):
$_FILES["file"]["name"] // the name of the uploaded file
$_FILES["file"]["type"] // the type of the uploaded file
$_FILES["file"]["size"] // the size in bytes of the uploaded file
$_FILES["file"]["tmp_name"] // the name of the temporary copy of the file stored on the server
$_FILES["file"]["error"] // the error code resulting from the file upload