我正在尝试通过带有 html 的类函数上传图像,但是我得到了 $_files 的空数组,请检查下面的脚本:
some of my class.php:
public function newsForm($news_array, $type){
list($news_id,$news_date,$news_title,$news_body,$img) = (is_array($news_array)) ? $news_array : array('','','','','');
$date_output = ($type=='update') ? '<p><label>First published:</label>'.$news_date.'</p>' : '';
$image = ($type == 'add') ? '<p><label for="image">Event Image:</label><input type="file" name="image" size="40"></p>' :'';
$escaped_body = (!empty($news_body)) ? htmlspecialchars($news_body) : '';
$tidy_action = ucfirst($type);
return <<<HTML
<form action="admin.php?action=$type" method="post" name="newsform">
<input name="type" type="hidden" value="$type" />
<p><label for="date">Date(dd-mm-yyy):</label><input name="d" type="date" value="$news_date" />
<input name="id" type="hidden" value="$news_id" />
<p><label for="title">Title:</label><input name="t" id="title" type="text" size="80" value="$news_title" /></p>
$date_output
<p><label for="article">Main Event:</label><textarea name="n" id="article" cols="50" rows="10" class="widgEditor nothing">$escaped_body</textarea></p>
$image
<p><input name="action" type="submit" value="$tidy_action Event" /> <a href="admin.php">Back to list</a></p>
</form>
HTML;
}
my some of admin.php:
if(isset($_FILES['image'])){
$thumb = $eve->upload();//which returns an array
$tt = $thumb[0];
$tn = $thumb[1];
$eve->insert_with_thunb($_POST['d'],$_POST['t'],$_POST['n'],$tn,$tt);
$page_content .= $pageMaker->notifyMessage('The Event was saved with image.');
$page_content .= $pageMaker->getNewsHTML($eve->getmembers());
}
当用户添加带有图像的表单时,记录未保存并生成未定义索引“图像”错误的通知。