我想对代码giniter中的文件上传字段进行验证。我尝试了以下代码,但这不起作用。还有别的吗?
<?php
$sql = 'SELECT name, description FROM pubs';
$where = [];
$params = [];
// If condition
// then add it to where
// $where[] = '(field1 = :field1)';
// $params[':field1'] = $_POST['field1'];
// If another condition
// then add to where
// $where[] = 'field2 = :field2';
// $params[':field2'] = $_POST['field2'];
// Combine where conditions (you may need to implement both AND and OR)
if (!empty($where)) {
$sql .= ' WHERE '.implode(' AND ', $where);
}
// Assuming this is your pdo object
$statement = $pdo->prepare($sql);
// Bind your parameter values
if (!empty($params)) {
foreach ($params as $key => $value) {
$statement->bindValue($key, $value, \PDO::_PARAM_STR);
}
}
// Then fetch the records
$statement->execute();
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
var_dump($result);
答案 0 :(得分:1)
除了使用javascript进行客户端验证外,您可以在控制器中尝试以下操作:
if (empty($_FILES['photo']['name']))
{
$this->form_validation->set_rules('photo', 'Passport photo', 'required');
}