我有一个表单,用于提交包含图像的新帖子。如果用户没有选择要上传的图像,我不希望帖子继续向服务器和数据库提交数据。目前我所做的一切都是让代码继续处理表单。
这是我的一些代码:
//check if the submit button has been clicked
if( isset( $_POST['submit'] ) ){
//validate the title and description
$title = validate_title($_POST['title']);
$desc = validate_desc($_POST['desc']);
//Get other posted variables
$cat = $_POST['cat'];
$year = $_POST['year'];
if($title && $desc != false){
//check if an image has been submitted
if( $_FILES['files']['name'] != ""){...
我也尝试过使用以下方法,但是在没有选择文件时都不会停止代码:
if( $_FILES['files']['error'] == UPLOAD_ERR_OK){...
if( $_FILES['files']['name'] != UPLOAD_ERR_NO_FILE){...