-2
我想從表單頁面上傳文件。如果我發佈照片文件,它會顯示在線數據庫和文件夾中的其中一個。上傳文件時出現語法錯誤,文件意外結束
這是從頁:
<form method="post" action="post_data.php" enctype="multipart/form-data">
<table align="center" class="monjey-tb">
<tr>
<td>
<label><span style="color:red">*</span>full name</label>
<input type="text" name="d_name" class="form-control" required /></td>
</tr>
<tr>
<td><br><label><span style="color:red">*</span>ID No.</label><input type="text" name="d_cpr" class="form-control" required /></td>
</tr>
<tr>
<td><br><label><span style="color:red">*</span>Address</label><input type="text" name="d_address" class="form-control" required /></td>
</tr>
<tr>
<td><br><label><span style="color:red">*</span>Mobile</label><input type="text" name="d_mobile" class="form-control" required /></td>
</tr>
<tr>
<td><br> <label><span style="color:red">*</span>Level</label> <div>
<select name="d_level" class="form-control" required>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</div>
</td>
</tr>
<tr>
<td><br><label><span style="color:red">*</span>Total</label><input type="text" name="d_total" class="form-control" required /></td>
</tr>
<td><br><label><span style="color:red">*</span>Photo1</label><input type="file" name="file" class="form-control" required/></td>
<tr>
</tr>
<td><br><label>photo2</label><input type="file" name="pphoto" class="form-control"/></td>
<tr>
</tr>
<td><br><label><span style="color:red">*</span>photo3</label><input type="file" name="certificate" class="form-control" required/></td>
<tr>
<td style="text-align: center"><br><button type="submit" name="submit"><strong class="j1">submint</strong></button></td>
</tr>
</table>
</form>
和後頁
<?php
include_once 'dbconfig.php';
if(isset($_POST['submit']))
{
//extract($_POST);
$d_name = $_POST['d_name'];
$d_cpr = $_POST['d_cpr'];
$d_address = $_POST['d_address'];
$d_mobile = $_POST['d_mobile'];
$d_level = $_POST['d_level'];
$file = rand(1000,100000)."-".$_FILES['file']['name'];
$certificate = rand(1000,100000)."-".$_FILES['certificate']['name'];
$pphoto = rand(1000,100000)."-".$_FILES['pphoto']['name'];
$file_loc = $_FILES['file']['tmp_name'];
$file_loc2 = $_FILES['certificate']['tmp_name'];
$file_loc3 = $_FILES['pphoto']['tmp_name'];
$file_size = $_FILES['file']['size'];
$file_type = $_FILES['file']['type'];
$folder="uploads/";
// variables for input data
$new_size = $file_size/1024;
$new_file_name = strtolower($file);
$final_file=str_replace(' ','-',$new_file_name);
if(move_uploaded_file($file_loc,$folder.$final_file))
{
if(move_uploaded_file($file_loc2,$folder.$final_file)){
if(move_uploaded_file($file_loc3,$folder.$final_file)){
// sql query for inserting data into database
$sql_query = "INSERT INTO users(d_name,d_cpr,d_address,d_mobile,d_level,file,type,size,certificate,pphoto)
VALUES('$d_name','$d_cpr','$d_address','$d_mobile','$d_level','$file','$file_type','$file_size','$certificate','$pphoto')";
mysql_query($sql_query);
header("Location: redir.php");
// sql query for inserting data into database
}
}
}
}
?>
附近if(move_uploaded_file($file_loc,$folder.$final_file))
帖子頁面上的問題。
我有3個文件
$ file_loc
和$ file_loc2
和$ file_loc3