나는 현재 프로젝트를 진행 중이며 사용자가 원하는 뉴스 헤드 라인, 기사 및 이미지를 만들 수 있습니다.이 시스템의 유일한 규칙은 기사와 이미지가 있어야한다는 것입니다. 내 질문은 내 양식에 내가 2 배열 하나를 $_POST
이고 다른 하나는 $_FILES
입니다 제출할 때입니다. $ _FILESPHP 배열 합치기
Array ( [article_image] => Array ( [name] => Array ( [0] => Intro-artists.gif [1] => textbg1.png ) [type] => Array ( [0] => image/gif [1] => image/png ) [tmp_name] => Array ( [0] => /private/var/tmp/phpwDAkGJ [1] => /private/var/tmp/phpmvrMDg ) [error] => Array ( [0] => 0 [1] => 0 ) [size] => Array ( [0] => 2841 [1] => 56506 ) ) )
는 기본적으로 데이터가 데이터베이스에 저장되어있는 양식을 제출 한 후 방법은 게시물의 3 개 항목이 저장 $ _POST
Array ( [campaign_title] => Another multiple test [campaign_keyword] => Another multiple test [introduction] => Another multiple test [campaign_headline] => Array ( [0] => Another multiple test headline 1 [1] => Another multiple test headline 2 ) [article] => Array ( [0] => Another multiple test article 1 [1] => Another multiple test article 2 ) [save_multiple] => Save )
한 테이블에서 헤드 라인과 기사는 방금 삽입 한 행의 ID로 전송 된 다른 테이블에 저장되고 마지막으로 이미지가 저장되고 첫 번째 저장 ID로 다시 전송됩니다 d 열.
올바른 이미지가 올바른 ID로 저장되는지 확인하는 데 문제가 있습니다. DB 저장은 헤드 라인과 기사를 반복하여 수행되지만 이미지는 다른 배열에 있으므로이 작업을 수행 할 수 없습니다. 그들이 올바른 외부 ID로 저장되는지 확인하십시오. 파일을 병합 할 수 있습니까? 현재 헤드 라인 및 기사에 대한 해결책은 다음과 같습니다.
foreach ($data['campaign_headline'] as $key => $headline) {
addMailerMultipleRelatedContent($mailerId, $headline, $data['article'][$key]);
}
function addMailerMultipleRelatedContent($mailerId, $headline, $article) {
extract($data);
//die(print_r($id));
$id = addRelatedMultipleContent($data['introduction'], $headline, $article,
$mailerId, mktime(), mktime());
}
function addRelatedMultipleContent($introduction, $headline, $content,
$mailer_id, $created_at, $updated_at){
$query = "INSERT INTO `mailer_content` (`id`, `introduction`, `headline`,
`content`, `mailer_id`,`created_at`, `updated_at`) VALUES ";
$query .= "(NULL, '" . makeSafe($introduction) . "', '" .
makeSafe($headline) . "', '" . makeSafe($content) . "', '" .
makeSafe($mailer_id) . "', " . makeSafe($created_at) . ", " .
makeSafe($updated_at) . ");";
$result = runInsert($query, __FUNCTION__);
//die(print_r($result));
return $result;
}
동시에 이미지 작업을 할 수 있습니까?
편집 :
HTML 양식,
<form method="post" action="/admin/editmultiple" enctype="multipart/form-data">
<fieldset class="toplined">
<label>Campaign Title</label>
<input type="text" name="campaign_title" value="<?echo (isset($mailers['mailer_title'])) ? $mailers['mailer_title'] : $_POST['campaign_title'];?>" class="extrawideinput" />
</fieldset>
<fieldset class="toplined">
<label>Campaign Type:</label>
<label>Multiple</label>
</fieldset>
<fieldset class="toplined">
<label>Campaign Keyword:</label>
<div class="forminputblock">
<input type="text" name="campaign_keyword" value="<?echo (isset($mailers['mailer_header'])) ? $mailers['mailer_header'] : $_POST['campaign_keyword'];?>" class="extrawideinput" />
</div>
</fieldset>
<fieldset class="toplined">
<label>Introduction</label>
<div class="forminputblock">
<input type="text" name="introduction" value="<?echo (isset($mailers['introduction'])) ? $mailers['introduction'] : $_POST['introduction'];?>" class="extrawideinput" />
</div>
</fieldset>
<fieldset class="toplined">
<label>Headline</label>
<div class="forminputblock">
<input type="text" name="campaign_headline[]" value="<?echo (isset($mailers['headline'])) ? $mailers['headline'] : $_POST['campaign_headline'];?>" class="extrawideinput" />
</div>
</fieldset>
<fieldset class="toplined">
<label>Image:</label>
<input type="file" name="article_image[]">
</fieldset>
<fieldset class="toplined">
<label>Story:</label>
<div class="forminputblock">
<textarea name="article[]" class="js_editable_textarea deeptext" rows="1" cols="1"><?echo (isset($mailers['content'])) ? $mailers['content'] : $_POST['article'];?></textarea>
</fieldset>
<div id="result">
</div>
<fieldset class="toplined">
<a href="" id="makeRequest">+ Add Another New Article</a>
</fieldset>
<fieldset class="toplined">
<input type="submit" name="save_multiple" value="Save" />
</fieldset>
</form>
http://www.php.net/manual/en/function.move-uploaded-file.php는 HTML 코드의 조각을 보내 주시기 바랍니다. 일반적으로 핵심은 양식 필드의 이름 지정입니다. –
제 편집 –