这是有效的,但是现在当我回到这个时,它就停止了工作。 我似乎无法弄清问题是什么。请帮忙。
<?php
if(isset($_POST['submit']))
{
require("dbconn.php");
$filename = $_POST['filename'];
$name = $filename . pathinfo($_FILES['ufile']['name'],PATHINFO_EXTENSION);
//$name = $_FILES['ufile']['name'];
echo $name;
//$size = $_FILES['file']['size']
//$type = $_FILES['file']['type']
$tmp_name = $_FILES['ufile']['tmp_name'];
$error = $_FILES['ufile']['error'];
if (isset ($name))
{
if (!empty($name))
{
$location = 'uploads/';
if (move_uploaded_file($tmp_name, $location.$name))
{
$filename = $_POST['filename'];
$filepath = $location.$name;
$advname = $_POST['advname'];
$year = $_POST['year'];
$cname = $_POST['cname'];
$ctype = $_POST['ctype'];
$sqlq = "INSERT INTO file (filename, filepath, advname, year, cname, ctype) VALUES ('".$filename."','".$filepath."','".$advname."','".$year."','".$cname."','".$ctype."');";
$result = mysql_query($sqlq);
if(!$result)
{
die("Error in connecting to database!");
}
}
}
}
}
?>
<form id="form1" method="POST" action="" enctype="multipart/form-data">
<label>File Name</label>
<input id="filename" name="filename" type="text" value=""/><br>
<label>Advocate Name</label>
<select name = "advname">
<option value=""></option>
<option value="Adv 1">Adv 1</option>
<option value="Adv 2">Adv 2</option>
<option value="Adv 3">Adv 3</option>
</select><br>
<label>Year<label>
<input id="year" name="year" type="date"><br>
<label>Company Name</label>
<input id="cname" name = "cname" type="text"><br>
<label>Court Type</label>
<input id="ctype" type="text" name = "ctype"><br>
<label>Scan</label>
<button type="button" class="btn btn-default" onclick="scanSimple();">Simple Scan</button>
<button type="button" class="btn btn-info" onclick="scan();">Scan</button><br>
<label>Upload</label>
<input type="file" name="ufile" id="ufile"><br>
<input type="submit" name="submit" value="Submit" onclick="submitForm1();">
</form>
这两个代码都是同一个文件的一部分。 请告诉我可能出错的地方,因为我似乎找不到任何错误。
我尝试在if语句中回显,但它没有显示任何内容。
答案 0 :(得分:0)
在我的php.ini文件中,我将post_max_size
设置为小于upload_max_filesize
,这就是创建此问题。
答案 1 :(得分:0)
您在表单标记的第一行中缺少action =“当前文件名”...
<form id="form1" method="POST" action="current file name/example.php" enctype="multipart/form-data">
或者使用它。
<form id="form1" method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>" enctype="multipart/form-data">