0

I have selected multiple image and show the preview in a div box. When I click on Save button, I want to get the information of the image using loop in PHP.

I try to echo the image_path for testing purpose, but it show nothing output.

HTML Form

<form id="photo-event-form" name="event-photo-gallery-form" class="form-horizontal" method="post" role="form" enctype="multipart/form-data">
<fieldset>

   <div class="control-group">                                          
      <label class="control-label" for="event_date">Event Photo</label>
      <div class="controls">
       : <input type="file" class="span3" id="pg_album" name="pg_album" multiple />

          <div id="form_button_div" class="form_button_div">
          <button id="test" name="pg_Save" type="submit" class="btn btn-primary">Save</button> 
          <button class="btn">Cancel</button>
   </div>
</fieldset>
</form>

PHP Save submit

if (isset($_POST['pg_Save'])) {

    $image_path = $_FILES['pg_album'];

    $i = 0;
    foreach ($Contents as $image_path) {
        $i++;
        echo $image_path;  //display image file path
    }
}
?>
2
  • where does $Contents come from? Commented May 22, 2014 at 2:02
  • @scrowler Sorry, this solution I reference from some answer from other question. I think this is a variable represent $image_path. Commented May 22, 2014 at 2:10

1 Answer 1

2

In your foreach loop you are overwriting the value of $image_path. So if it had the right value (it doesn't) it is gone before you attempt to use it.

Additionally, you cannot get the file path as it resided on the user's computer. That information is not provided and thus not available to you. If you want to know what information is available to you, read the PHP manual on handling file uploads.

Sign up to request clarification or add additional context in comments.

4 Comments

Yes..I understand that..but in previous..I able to get the file name and file size using $_FILES['file']['name'] or $_FILES['file']['size']..
That info will be available to you in $image_path if you fix the first error I mentioned.
Any solution that able to provide a loop through the image I selected? Example I selected 3 image and preview it..when click on submit button..I want to loop the three image and get each of the image information such as SIZE..?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.