2

クラス関数を使用して html で画像をアップロードしようとしていますが、$_files の null 配列を取得しています。以下のスクリプトを確認してください。

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" />&nbsp;<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());

}

ユーザーが画像を含むフォームを追加すると、レコードが保存されず、未定義のインデックス「画像」エラーの通知が生成されました。

4

1 に答える 1

0

formタグを変更して、マルチパート エンコーディング属性を含めます。

<form enctype='multipart/form-data' action="admin.php?action=$type" method="post" name="newsform">

これにより、フォーム データでファイルを送信できます。デフォルトでapplication/x-www-form-urlencodedは、単純なクエリ文字列としてエンコードされ、ファイル データは含まれません。

続きを読む

于 2013-10-22T14:51:56.760 に答える