我在大学项目中遇到问题,我们创建了图书注册表。然而,到目前为止,我们有一个插入书籍封面的部分。无论如何尝试,文件不发送。我创建了一个要测试的新目录,它也没有用。请遵循以下代码:
<form enctype="multipart/form-data" method="post" action="index.php">
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<input type="file" name="cover"/>
<input type="submit" name="insert" class="btn btn-primary" value="Insert Data">
</form>
<?php
if(isset($_POST['insert'])):
$destiny = '/' . $_FILES['cover']['name'];
$tmp_file = $_FILES['cover']['tmp_name'];
move_uploaded_file( $tmp_file, $destiny);
var_dump($_FILES);
endif;
?>
单击“提交”而不选择任何文件时,它通常属于IF。但是,在提交文件并单击“提交”时,没有任何反应。仅重新加载页面。试图把正确的命运投入并继续做同样的事情。
编辑:
我收到以下错误:
警告:POST内容长度为3724451字节超过第0行未知的3145728字节限制
答案 0 :(得分:0)
解决!
感谢@fillipo和@Masivuye以及其他人的帮助。
我做了什么:
更改了php.ini中的最大大小,在index.php中创建了files文件夹,并从HTML中删除了max_size属性。现在就开始工作!
答案 1 :(得分:0)
<form enctype="multipart/form-data" method="post" action="index.php">
<input type="file" name="cover"/>
<input type="submit" name="insert" class="btn btn-primary" value="Insert Data">
</form>
<?php
if(isset($_POST['insert'])):
$target_dir = "uploads/";
$destiny = $target_dir . basename($_FILES['cover']['name']);
$tmp_file = $_FILES['cover']['tmp_name'];
$uploadOk = 1;
// Check file size
if ($_FILES["cover"]["size"] > 30000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($tmp_file, $destiny)) {
echo "The file ". basename( $_FILES["cover"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
var_dump($_FILES);
endif;
?>