我有一个页面(添加帖子),它需要来自用户的输入。但在帖子文件中我不希望它是强制性的。我希望用户可选地插入文件。
怎么做?
if($file_size > 2097152){
$missing_input[]='The Post image must be less that 2MB';
}
if($file_size1 > 2097152){
$missing_input[]='The Post file must be less that 2MB';
}
if($_FILES['image']['error'] == UPLOAD_ERR_NO_FILE){
$target = "../posts/default.png";
$check_upload = true;
} else {
$target = "../posts/". rand()*78789685 . $file_name;
$check_upload = move_uploaded_file($file_tmp,$target);
}
if($_FILES['file']['error'] == UPLOAD_ERR_NO_FILE){
$missing_input[]='The Post file must be selected';
} else {
$target1 = "../posts/". rand()*789789789 . $file_name1;
}
$user_id = $_SESSION['student_id'];
$course_id = $_GET['course_id'];
if(empty($missing_input) and $check_upload and move_uploaded_file($file_tmp1,$target1))
{
$sql="INSERT INTO posts VALUES(NULL,'$title', '$desc', '$target', '$target1', $user_id, $course_id, NOW(), 1)";
//echo $sql . "<br>";
$result2= mysqli_query($connection,$sql);
if($result2) {
echo "<div class='alert alert-success' style='max-width:460px; margin: 4px auto'>";
echo 'Your Post Published';
echo "</div>";
if($result2) {
echo '<META HTTP-EQUIV="Refresh" Content="2; URL=index.php?p=posts"/>';
exit;
}
}
} else {
foreach($missing_input as $e) {
echo "<div class='alert alert-danger' style='max-width:500px; margin: 4px auto'>";
echo $e;
echo "</div>";
}
}
}
?>