我想创建一个编辑文件表单,您可以在其中选择要上载的其他文件并替换以前的文件。这是我的代码。
<?php
require("config.php");
$id = $_GET['id'];
$sql = "SELECT * FROM contracts WHERE id= '$id'";
$result = $con->query($sql);
while ($row = $result->fetch_assoc())
{
?>
<html><head></head>
<body>
<form method="GET" action="" enctype="multipart/form-data">
ID: <?php echo $id; ?><br>
<input type="hidden" name="id" value="<?php echo $id; ?>" />
Upload File:
<input type="file" name="upload" value="<?php echo $row($_FILES['name']) ?>"/><br>
<input type="submit" name="submit" value="Submit"/>
</form>
</body>
</html>
<?php
}
if(isset($_GET['edit']) ){
if ($_FILES['upload']['size'] != 0 ){
$filename = $con->real_escape_string($_FILES['upload']['name']);
$filedata= $con->real_escape_string(file_get_contents($_FILES['upload']['tmp_name']));
$filetype = $con->real_escape_string($_FILES['upload']['type']);
$filesize = intval($_FILES['upload']['size']);
$query = "UPDATE `contracts` set `filename` = '$filename',`filedata` = '$filedata', `filetype` = '$filetype',`filesize` = '$filesize' WHERE `id` = '$id' " ;
if ($con->query($query) == TRUE) {
echo "<br><br> New record created successfully";
} else {
echo "Error:<br>" . $con->error;
}
} else {
$filename = $con->real_escape_string($_FILES['upload']['name']);
$filetype = $con->real_escape_string($_FILES['upload']['type']);
$filesize = intval($_FILES['upload']['size']);
$query = "UPDATE `contracts` set `filename` = '$filename', `filetype` = '$filetype',`filesize` = '$filesize' WHERE `id` = '$id' " ;
if ($con->query($query) == TRUE) {
echo "<br><br> New record created successfully";
} else {
echo "Error:<br>" . $con->error;
}
}
$con->close();
}
?>
有人可以告诉我,我做错了什么吗?
答案 0 :(得分:0)
正确的编码应该是
Upload File:
<?php echo $row['filename'] ?>
<input type="file" name="upload"/><br>
<input type="submit" name="edit" value="Submit"/>