Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 933317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:48:55+00:00 2026-05-15T20:48:55+00:00

I am working on a project at the moment, that allows the user to

  • 0

I am working on a project at the moment, that allows the user to create any number of news headlines, articles and images, the only rule with this system is that a headline must have an article and an image. My question is on my form when I submit I get 2 arrays one is the $_POST and the other is $_FILES.

$_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
)

$_FILES

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
    )

  )

)

Basically the method after submitting the form is the data is saved to a database, the 3 items of the post are saved in one table, the headlines and articles are saved in another table (sent with the id of the row just inserted) and then finally the images are saved, again sent with id of the first saved row.

I am having trouble understanding how I make sure the right images gets saved with the right ID, the DB saves are done by looping through the headlines and articles, but as the images are in a different array I cannot do this and make sure they are getting saved with right foreign id, can I merge the files into the post? Currently the solution I have for the headlines and articles is this,

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;
}

Is there away for me to work with images at the same time?

EDIT:

The HTML form,

<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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T20:48:56+00:00Added an answer on May 15, 2026 at 8:48 pm

    With the same key you use to access the articles sub array, you can access the different fields in the $_FILES array. Obviously you can merge the two arrays, but it isn’t necessary for you to work with them.

    Also, you should note that you have to copy the actual data from the temporary location to where ever you would like to permanently store it. Make sure to use the [is_uploaded_file()][1] and [move_uploaded_file()][2] methods to prevent potential attacks via file uploads.

    [1]: http://www.php.net/manual/en/function.is-uploaded-file.php is_uploaded_file()
    [2]: http://www.php.net/manual/en/function.move-uploaded-file.php move_uploaded_file()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a project were we have number (5 at the moment) of
I'm working on a project at the moment that involves building a system in
The project that I'm working on at the moment uses an IDisposable object in
I am currently working on a project to create simple file uploader site that
At this moment, I am the only person working on a project in svn.
Working on a project at the moment and we have to implement soft deletion
At the moment I am working on a project admin application in C# 3.5
Ok I'm working on a little project at the moment, the Report expects an
A project I'm working on at the moment involves refactoring a C# Com Object
I am working a project that does not have a trunk / branches /

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.